Skip to content

Instantly share code, notes, and snippets.

@bokuo-okubo
Created November 25, 2015 10:46
Show Gist options
  • Save bokuo-okubo/8f5b92a974602a6c8167 to your computer and use it in GitHub Desktop.
Save bokuo-okubo/8f5b92a974602a6c8167 to your computer and use it in GitHub Desktop.
class Person
@name
def hello
p @name ||= 'Michael'
end
end
man = Person.new
man.hello # => "Michael"
man.name # => NoMethodError: undefined method `name' for #<Person:0x007f9823877f68 @name="Michael">
man.instance_eval { @name = 'John' }
man.hello # => "John"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment