Sender
A rather pointless little program.. just playing and testing.
class Enumerator
alias :e :each
end
# -----------------------------------------------------------------------------
# hash of send-array containing args
c = {
op: [:puts, :self], # OutPut => puts str
uc: [:self, :upcase], # UpCase => str.upcase
en: [:self, :to_enum], # Enum => ar.to_enum
}
c.instance_exec {
def →(cmd, *args)
(self[cmd][0] == :self) ?
args[0].send(self[cmd][1]) :
send(self[cmd][0], *args)
end
}
# -----------------------------------------------------------------------------
# hash of procs
» = {
puc: proc {|str| c.→(:op, c.→(:uc, str)) }, # puts UPCASE
en: proc {|ar| c.→(:en, ar) }, # return Enumerator
}
».instance_exec {
def method_missing(key, *args)
self.key?(key) ? self[key][*args] : super
end
}
# -----------------------------------------------------------------------------
# example call
».en([*1..5]).e { ».puc("hej: #{it}") }
# => output
# HEJ: 1
# HEJ: 2
# HEJ: 3
# HEJ: 4
# HEJ: 5