so I'm trying this code out,
class Colors
def initialize color
color.each {|c| color c}
end
def color c
self.class.send(:define_method, "about_#{c}") do
puts "The color #{c} has an intensity of #{Random.rand}"
end
end
end
a = Colors.new(["orange", "pink", "yellow", "green"])
a.about_pink
a.about_pink
a.about_pink
On my machine I get:
The color pink has an intensity of 0.377090691263002
The color pink has an intensity of 0.8375972769713161
The color pink has an intensity of 0.26820920750202837
the problem is that 4 statements each with a different number are printed. Shouldn't all the statements printed contain the same random number as the method is "defined" only once?