Created
January 17, 2011 19:44
-
-
Save bklang/783339 to your computer and use it in GitHub Desktop.
In Ruby 1.8 sending :attr_accessor to an object resulted in a public accessor method. In Ruby 1.9 the methods are private.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
attr_accessor :x | |
end | |
Foo.send(:attr_accessor, :y) | |
myfoo = Foo.new | |
# Using the attr_accessor defined initially works fine | |
myfoo.x = 1 | |
# Using the attr_accessor defined at runtime gies NoMethodError | |
myfoo.y = 1 | |
NoMethodError: private method `y=' called for #<Foo:0x000001008f6be0 @x=1> | |
from (irb):9 | |
from /Users/bklang/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `<main>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment