From: Austin Ziegler Date: 2005-08-12T03:48:22+09:00 Subject: Re: Dynamically added methods On 8/11/05, Yann Klis wrote: > Hi all, > > I'm pretty new to ruby so I will ask some dumb questions, sorry if it's > not the right place to ask :) > > I'd like to add some methods dynamically to one of my object. > I understand that with "method_missing" I can "emulate" this behaviour. > > However, imagine I have an hash table. The key would be the attributes > of my object, and the keys their value. How could I add dynamically > accessors for those attributes/keys ? Use OpenStruct. require 'ostruct' os = OpenStruct.new os.foo = "hello" os.bar = "world" puts "#{os.foo}, #{os.bar}" -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca