From: Ken Bloom Date: 2007-08-20T01:40:03+09:00 Subject: Re: Array Difference On Sun, 19 Aug 2007 13:22:13 +0200, Robert Klemme wrote: > On 18.08.2007 01:05, Ken Bloom wrote: >> On Fri, 17 Aug 2007 22:17:25 +0200, Robert Klemme wrote: >>> If you need more methods you can use a block: >>> >>> Prova = Struct.new :n do >>> def your_method(x) >>> x + n >>> end >>> end >> >> Thanks for the tip, I've tried to do things like >> >> class Foo < Struct.new(:a,:b) >> def method >> end >> end >> >> and while it works, it felt sorta hackish. > > If by "hackish" you mean that this creates one additional class then > yes, sort of. Other than that it's ok, but I usually prefer the non > inheritance version in these cases since only one class is needed. > > Kind regards > > robert I've tried two ways actually Foo=Struct.new(:bar,:baz) class Foo def method end end and the inheritance method I've described above. You know what really makes it seem hackish? RDoc. I'd like RDoc to document both the attributes of a Struct on normal class listing, and also document the methods that I create on those Structs in the same page. --Ken -- Ken Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/