From: Jan Svitok Date: 2006-10-18T22:16:02+09:00 Subject: Re: Struct (not) accepting attributes On 10/18/06, Robert Klemme wrote: > On 18.10.2006 14:33, Kero wrote: > >> Sum = Struct.new(:bla, :"sum(value)") > >> sum = Sum.new(2, 5) > > => # > >> sum.send(:"sum(value)") > > NoMethodError: undefined method `sum(value)' for # > >> class X > >> attr_accessor :"sum(value)" > >> end > > NameError: invalid attribute name `sum(value)' > >> class Sum > >> define_method(:"sum(value)") { "summum!" } > >> end > > => # > >> sum.send(:"sum(value)") > > => "summum!" > > > > Not sure this is an error in ruby (1.8.5) or a misunderstanding from me (about Struct). > > There is another option: a misunderstanding on your side which attribute > names can be used in this situation / generally. As you see your sample > class X does not work either. > > Why don't you just use "sum_value" as attribute name? > > Kind regards > > robert sum(value) is not a valid method name. method names must match (I believe) /[a-z_][a-zA-z0-9_]+[?!]?/ if you want to have a struct with additional method do this: class Sum < Struct.new(:blah) def sum(value) ... end end