From: Logan Capaldo Date: 2007-09-05T07:58:13+09:00 Subject: Re: Struct is cleverer than the documentation claims On 9/4/07, Daniel DeLorme wrote: > Robert Klemme wrote: > > Why should I reopen a class if I can have everything with the block? > > > > Customer = Struct.new :name, :address do > > def to_s > > "Customer called '#{name}' living at '#{address}'" > > end > > end > > because, say, you'd want to add a constant to that class > Customer = Struct.new :name, :address do > K = 42 > end > Customer::K > (irb):7: warning: toplevel constant K referenced by Customer::K > This is workaroundable, if a bit ugly as I recently learned: Customer = Struct.new :name, :address do self::K = 42 end Customer::K > Daniel > >