Sebastian Hungerecker
5/26/2009 8:42:00 PM
Am Dienstag 26 Mai 2009 00:05:07 schrieb kunjaan:
> What do you mean when you say"Class definitions are executable code".
It means that class definiton happens at runtime. You can have any valid ruby
expressions inside a class body, and they will be executed as they encountered
by the parser. Example: loops:
class Foo
(1..9).each do |i|
define_method("add#{i}") do |x|
x+i
end
end
end
Foo.instance_methods(false)
#=>["add2", "add9", "add5", "add1", "add8", "add4", "add7", "add3", "add6"]
Foo.new.add5(6)
#=> 11