Project

General

Profile

Actions

Bug #1983

closed

Struct doesn't define instance methods for valid method names

Added by bitsweat (Jeremy Daer) over 15 years ago. Updated over 13 years ago.

Status:
Rejected
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)
=> #<struct :foo?=true, :foo!=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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0