Skip to content

Instantly share code, notes, and snippets.

@lolmaus
Created May 15, 2012 13:47
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 lolmaus/2701912 to your computer and use it in GitHub Desktop.
Save lolmaus/2701912 to your computer and use it in GitHub Desktop.
class MyClass
def i_understand_how_this_works(local_var)
@the_string ||= "omg"
@the_string << local_var
end
def how_is_that_possible
@the_string ||= "omg"
end
def put
puts "> #{@the_string}"
end
end
vasya = MyClass.new
vasya.put # >
vasya.i_understand_how_this_works " wtf"
vasya.put # > omg wtf
vasya.how_is_that_possible << " igo"
# It modifies an instance var without
# either exposing it via attr_writer
# or doing an assignment withing the method!
vasya.put # > omg wtf igo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment