Skip to content

Instantly share code, notes, and snippets.

@samflores
Created March 5, 2013 14:42
Show Gist options
  • Save samflores/5090741 to your computer and use it in GitHub Desktop.
Save samflores/5090741 to your computer and use it in GitHub Desktop.
I found something like this in a blog post. I agree with the post subject, just don't understand why the author choose the following idiom
foo = case value
when nil
NullObject.new
else
value
end
@samflores
Copy link
Author

por que não:

foo = if value
  value
else
  NullObject.new
end

ou

foo = value.nil? ? NullObject.new : value

ou ainda

foo = value || NullObject.new

@dmitryrck
Copy link

foo = value || NullObject.new

É bem melhor :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment