Array#to_proc
Symbol#pa - かきにっき
なるほどキモイスバラシイ。
class Symbol def [] *arg me = self proc{|o, *a| o.__send__ me, *arg, *a } end end module Enumerable def ^ p map &p end end p (0..4)^:to_s[2] #=> ["0", "1", "10", "11", "100"]
これでGroovyの「(0g..4g)*.toString(16)」にも負けない。cutはこうかな。
class X; end class Array def to_proc me = dup me << X unless me.index X proc{|*x| rcv, sym, *arg = me.map{|a| a == X ? x.shift : a } rcv.__send__ sym, *arg } end end p (5..9)^['%b', :%] #=> ["101", "110", "111", "1000", "1001"] p 'hoge'.chars.with_index^[X, :*, X] #=> ["", "o", "gg", "eee"] p [:+, :-, :*, :/]^[42, X, 13] #=> [55, 29, 546, 3]
使い途が有るような無いような。