Project

General

Profile

Bug #1983

Struct doesn't define instance methods for valid method names

Added by bitsweat (Jeremy Daer) over 11 years ago. Updated over 9 years ago.

Status:
Rejected
Priority:
Normal
Target version:
ruby -v:
ruby 1.9.2dev (2009-08-16) [i386-darwin9.8.0]
Backport:
[ruby-core:25066]

Description

=begin

foo = Struct.new(:foo?, :foo!).new(true, true)
=> #
foo.foo?
NoMethodError: undefined method foo?' for #<struct :foo?=true, :foo!=true>
from (irb):3
from /usr/local/bin/irb19:12:in
'
foo.foo!
NoMethodError: undefined method foo!' for #<struct :foo?=true, :foo!=true>
from (irb):4
from /usr/local/bin/irb19:12:in
'
foo[:foo?]
=> true
foo[:foo!]
=> true

I think this is because foo?= and foo!= are not valid setter methods.

By why not generate the reader and skip the setter, then?
=end

Also available in: Atom PDF