Skip to content

Instantly share code, notes, and snippets.

@sherpc
Created April 20, 2013 20:56
Show Gist options
  • Save sherpc/5427400 to your computer and use it in GitHub Desktop.
Save sherpc/5427400 to your computer and use it in GitHub Desktop.
# Пусть магический метод называется 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