2006/5/6, Frank Hirsch <0ffh / frankhirsch.net>:
>
> Hija!
>
> I have made a little record class, because I needed it.
>
> Maybe anyone finds this useful, or wants to beat me,
> because I have overtreaden some unwritten Ruby rule... :-)))
>
> >---------------- cut here ----------------<
>
> class Record
> =begin
> Little record class.
> (w) Frank Hirsch 2006
> =end
>   def method_missing(*a)
>     if (a.length!=2)
>       super
>     elsif (a[0].class!=Symbol)
>       super
>     else
>       name=a[0].id2name
>       value=a[1]
>       eval("@"+name+"value",binding)
>       eval("def "+name+"(v);@"+name+"v;end")
>       name.chop!
>       eval("def "+name+";@"+name+";end")
>     end
>   end
>   def initialize
>   end
> end
>
> >---------------- and here ----------------<
>
> Okay, what does anybody think?
> Useful or heresy or just an old hat?

This looks like another implementation of OpenStruct...

irb(main):027:0> require 'ostruct'
=> true
irb(main):028:0> rec = OpenStruct.new
=> #<OpenStruct>
irb(main):030:0> rec.name
=> nil
irb(main):031:0> rec.name="foo"
=> "foo"
irb(main):032:0> rec.name
=> "foo"

Kind regards

robert

--
Have a look: http://www.flickr.com/photos/fussel-foto/