class Out
attr_writer :frm, :meth
def initialize(frm = '%s', meth = :puts) =
( @frm, @meth = frm, meth )
def →(*ar) = ( send @meth, @frm % [*ar] )
end
class Array
alias_method :đ, :first
alias_method :ł, :last
(0..9).each {|no| define_method(:"_#{no}") { self[no] } }
end
class String
def ĸ(rx, &bl) = ( scan(rx).each &bl )
end
O = Out.new('%s: %s')
def →(*args) = ( O.→(*args) )
# ==========================================
str = %(one 1 two 2 three 3 four 4)
str.ĸ(/(\w+) (\d)/) { → _1.đ, _1.ł }
O.frm = '%s'; O.meth = :p
→ [1,2,3]._0 # => 1
→ %w(one two three)._2 # => three
→ %(hejsan hoppsan i lingonskogen).split(' ')._3 # => lingonskogen
---------------------------------------------
ĸ is scan(REGEX).each { BLOCK }
→ is Out.→
and uses output format defined with Out.frm
and a print method defined with Out.meth
đ is Array#first
ł is Array#last
_0 .. _9 is Array index [0] .. [9]