Skip to content

Instantly share code, notes, and snippets.

@bklang
Created January 17, 2011 19:44
Show Gist options
  • Save bklang/783339 to your computer and use it in GitHub Desktop.
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.
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