I’m no metaprogramming wizard… I keep trying variations until it
works.This seems to work.
class YourClass
def []=(f, v)
class << self; self end.instance_eval{ attr_accessor f };
instance_eval “@#{f}=v”
end
end
Oops… I forgot to put up a new one-liner question! (Don’t forget you
guys!!!)
Here’s something simple: define method roll(n, s) to roll a s-sided
die n times and display a bar graph of the results. So roll(20, 4)
might look like this:
1|#####
2|#####
3|######
4|####
This seems to work.
