require 'mw_oxcart.rb'
Ox = Before::cart {
→ :names, %w(olle kalle pelle)
→ (:uc) {|s| s.upcase }
→ (:mp) {|ar, proc| ar.map &proc }
→ :just, '%10s'
→ (:op) {|n| '%s%s%s' % [Ox.just(n), "\n", Ox.just('-'*n.size)]}
→ :add, :+
→ :mult, :*
→ :str, 'hej baberiba!'
→ :str2, 'hej baberiba.. %s!'
→ :name, '%s är %s år.'
→ :Pall, :Mall
}
p Ox.names.map &:upcase # => ["OLLE", "KALLE", "PELLE"]
p Ox.names.map &Ox[:uc] # => ["OLLE", "KALLE", "PELLE"]
p Ox.mp Ox.names, Ox[:uc] # => ["OLLE", "KALLE", "PELLE"]
p Ox.str # => "hej baberiba"
p Ox.str2 :koskit # => "Hej baberiba.. koskit!"
p Ox.name :anna, 7 # => "Anna är 7 år."
Ox.names << 'bo'
p Ox.names.join ?, # => "olle,kalle,pelle,bo"
p Ox.names.pop # => "bo"
p Ox.names.last # => "pelle"
Ox.names = %w(ewa ragnhild lise-lott)
p Ox.names # => ["ewa", "ragnhild", "lise-lott"]
Ox.names.each {|name| puts Ox.op name }
#
# => ewa
# => ---
# => ragnhild
# => --------
# => lise-lott
# => ---------
# ( 3 + 2 = 5 / 3 * 2 = 6 )
%i(add mult).each { p 3.send(Ox.send(_1), 2) }
# => 5
# => 6