If I create a Struct with an attribute which contains a question mark, any instance of that class will not be able to find that method. For e.g.
Test = Struct.new(:value, :value?)
t = Test.new(true,true)
t.value
=> true
t.value?
NoMethodError: undefined method `value?' for #<struct Test value=true, :value?=true>
Any idea ? I am using Ruby 1.9.3-p286.
Yo’ll have to concede that some method names in Ruby are special. For example, if you defined method
And call
The result will still be 1, not 2 as you might expect. This is peculiarity of
=sign in method names. In your case of Structs, question mark seems to have such peculiarity, too, which prevents you from retrieving value by calling:You have to call
That’s it, have a nice day.