Created
January 20, 2014 17:52
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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