Skip to content

Instantly share code, notes, and snippets.

@demental
Created April 17, 2013 08:24
Show Gist options
  • Save demental/5402668 to your computer and use it in GitHub Desktop.
Save demental/5402668 to your computer and use it in GitHub Desktop.
Beware that inline statements in ruby uses Proc
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