Skip to content

Instantly share code, notes, and snippets.

@danbernier
Created January 8, 2012 21:20
Show Gist options
  • Save danbernier/1579738 to your computer and use it in GitHub Desktop.
Save danbernier/1579738 to your computer and use it in GitHub Desktop.
Ruby lets you add instance variables at runtime
ruby-1.9.2-p290 :001 > class Foo
ruby-1.9.2-p290 :002?> def bonk
ruby-1.9.2-p290 :003?> @bonk = nil
ruby-1.9.2-p290 :004?> end
ruby-1.9.2-p290 :005?> end
=> nil
ruby-1.9.2-p290 :006 > f = Foo.new
=> #<Foo:0x007ff15c1e65b8>
ruby-1.9.2-p290 :007 > f.bonk
=> nil
ruby-1.9.2-p290 :008 > f.inspect
=> "#<Foo:0x007ff15c1e65b8 @bonk=nil>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment