Metaprogramming with Darkie The Fridge
m = "mr_beastly_"
(1..50).collect { |darkie_the_fridge|
thefun = m + darkie_the_fridge.to_s + "!"
eval %{
def #{thefun}(cinnamocha)
puts cinnamocha * #{darkie_the_fridge}
end
}
}
mr_beastly_5! 'boogiebot '
The result of this is boogiebot boogiebot boogiebot boogiebot boogiebot.
Trackbacks
Use this link to trackback from your own site.







how would you call the function from the created array, like
a = (1..50).collect {………..}
then if you’d call a[5] ‘boogiebot’, it would return the same output as mr_beastly_5! ?
Problem is, the collect has to return a proc or the assignment would yield nil. Consider the following example.
Output is
Also, try out variations with irb.