Skip to content

Instantly share code, notes, and snippets.

@SamGerber-zz
Created December 9, 2015 06:41
Show Gist options
  • Select an option

  • Save SamGerber-zz/632abef7a56370c0547a to your computer and use it in GitHub Desktop.

Select an option

Save SamGerber-zz/632abef7a56370c0547a to your computer and use it in GitHub Desktop.
Setting Instance Variables with a Setter Method
class Universe
def answer=(something)
@answer = something
end
end
universe = Universe.new # => #<Universe:0x007f639f31b8e8>
universe.instance_variables # => []
universe.answer = "42" # => "42"
universe.instance_variables # => [:@answer]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment