Created
April 20, 2013 20:56
-
-
Save sherpc/5427400 to your computer and use it in GitHub Desktop.
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
# Пусть магический метод называется defnil | |
# Тогда обычный вариант: | |
def f(x,y) | |
return nil if x == nil | |
x + y | |
end | |
f(1,2) # => 3 | |
f(nil,2) # => nil | |
# Или новый: | |
defnil f(x,y) | |
x + y | |
end | |
f(1,2) # => 3 | |
f(nil,2) # => nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment