From: Matthew Moss Date: 2008-09-20T22:35:34+09:00 Subject: Re: One-Liners Mashup (#177 again) > I didn't really have a problem in mind, but here's an easy one: Write an []= > method to solve the following: > > obj = YourClass.new > obj['answer'] = 42 > obj.answer  # => 42 I'm no metaprogramming wizard... I keep trying variations until it works. :D This seems to work. class YourClass def []=(f, v) class << self; self end.instance_eval{ attr_accessor f }; instance_eval "@#{f}=v" end end