The wonders of Ruby:
[/cygdrive/c/temp H:103 (last=0) 10:18:59]$ t.rb
via: [1, 2, 3]
bar: [1]
bar: [2]
bar: [3]
foo: [1, 2, 3]
[/cygdrive/c/temp H:104 (last=0) 10:19:02]$ cat t.rb
#!/usr/bin/ruby
def bar(*args)
puts “bar: %s” % [args.inspect]
end
def foo(*args)
puts “foo: %s” % [args.inspect]
end
def via( meth1, meth2, *params)
puts “via: %s” % [params.inspect]
params.each { |par|
method(meth1).call(par)
}
method(meth2).call(*params)
end
via(:bar, :foo, 1,2,3)
···
-----Original Message-----
From: Elias Athanasopoulos [mailto:elathan@phys.uoa.gr]
Sent: Sunday, 8 February 2004 6:37 AM
To: ruby-talk ML
Subject: [RFC] ‘via’ proposal
Hello!
Well, just a thought… Consider that:
1000.times do |a, b, c|
a = …
b = …
c = …
bar a
bar b
bar c
foo
end
Okay, this is a bad design, but let’s say that I can’t change it. Can a
Ruby syntax structure like the one below constructed in an (almost) easy
way?
via bar foo do |a, b, c|
a = …
b = …
c = …
end
i.e. can I construct in pure Ruby or via a C extension a 'via’
method for Object, which will enhance:
foo do { |…| … }
in a way, that all block arguments will be passed in another method
before the end of the block?
If all these do not make sense, just forgive me. It’s night here.
Regards,
University of Athens I bet the human brain
Physics Department is a kludge --Marvin
Minsky