Skip to content

Instantly share code, notes, and snippets.

@ctdean
Last active December 26, 2015 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctdean/7222190 to your computer and use it in GitHub Desktop.
Save ctdean/7222190 to your computer and use it in GitHub Desktop.
class Foo
attr_accessor :color
attr_accessor :history
def initialize
@color = "white"
@history = [@color]
end
def dump
"color = <#{@color}>, history = <#{@history}>"
end
def reset_1
color = "red"
history << "red"
end
def reset_2
self.color = "green"
self.history << "green"
end
def reset_3
@color = "blue"
@history << "blue"
end
end
foo = Foo.new
puts "start #{foo.dump}"
foo.reset_1
puts "reset_1 #{foo.dump}"
foo.reset_2
puts "reset_2 #{foo.dump}"
foo.reset_3
puts "reset_3 #{foo.dump}"
@ctdean
Copy link
Author

ctdean commented Oct 30, 2013

results in:

start color = <white>, history = <["white"]>
reset_1 color = <white>, history = <["white", "red"]>
reset_2 color = <green>, history = <["white", "red", "green"]>
reset_3 color = <blue>, history = <["white", "red", "green", "blue"]>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment