Skip to content

Instantly share code, notes, and snippets.

@acook
Created January 20, 2014 17:52
Show Gist options
  • Save acook/8525220 to your computer and use it in GitHub Desktop.
Save acook/8525220 to your computer and use it in GitHub Desktop.
Even with an explicit return, setters always return the original value. This makes some sense, but it can be a gotcha if you're doing something special like accepting a string an setting a File object, instead of getting the file back, you'll still get the string.
class Foo
def bar= new_bar
return "MEGAZOIDS"
end
end
f = Foo.new
p f.bar = "lolcats" #=> "lolcats"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment