Skip to content

Instantly share code, notes, and snippets.

@ynojima
Created November 24, 2012 01:56
Show Gist options
  • Save ynojima/4138027 to your computer and use it in GitHub Desktop.
Save ynojima/4138027 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
class InstanceVariableEval
attr_accessor :val
def initialize
@val = "initial data"
end
def set_from_instance_method_through_accessor
val = "set_from_instance_method_through_accessor"
end
end
a = InstanceVariableEval.new
puts a.val
a.set_from_instance_method_through_accessor
puts a.val
a.val = "set_through_accessor"
puts a.val
## Following is the output. I can't understand why val is not updated by the method "set_from_instance_method_through_accessor".
# initial data
# initial data
# set_through_accessor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment