Created
April 17, 2013 08:24
-
-
Save demental/5402668 to your computer and use it in GitHub Desktop.
Beware that inline statements in ruby uses Proc
This file contains hidden or 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 MyClass | |
class << self | |
def with_inline_statement | |
result = nil | |
response = result.first if(result = item).exists? | |
response | |
end | |
def with_multiline_statement | |
if (result = item).exists? | |
response = result.first | |
end | |
response | |
end | |
def item | |
ClassWithExists.new | |
end | |
end | |
end | |
class ClassWithExists | |
def exists? | |
true | |
end | |
def first | |
'youhou' | |
end | |
end | |
puts 'WITH MULTILINE' | |
p MyClass.with_multiline_statement | |
puts 'WITH INLINE' | |
p MyClass.with_inline_statement |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment