From: Austin Ziegler Date: 2006-11-12T11:43:40+09:00 Subject: Re: Can Ruby do this magic... elegantly On 11/11/06, J2M wrote: > I would like to be able to be able to include instance methods of a > Struct into a class. e.g. > > foo = Struct.new(:attribute, :another_attribute) > bar = foo.new > > class Bas > > some_ruby_magic > > end > > So that I can then do > > Bas.attribute="a value" > Bas.attribute > > Kind of like doing module_functions but that doesn't work inside a > class. class Bas @__struct__ = Struct.new(:attribute, :another_attribute) class << self def method_missing(sym, *args) @__struct__.send(sym, *args) if @__struct__.respond_to?(sym) end end end That should work. -austin -- Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/ * austin@halostatue.ca * http://www.halostatue.ca/feed/ * austin@zieglers.ca