Skip to content

Instantly share code, notes, and snippets.

@rwz
Created February 8, 2012 06:39
Show Gist options
  • Save rwz/1766091 to your computer and use it in GitHub Desktop.
Save rwz/1766091 to your computer and use it in GitHub Desktop.
A little rubyquiz
my_object.bool_method?? 'yes' : 'no'
# or
my_object.bool_method? ? 'yes' : 'no'
# or
(my_object.bool_method?) ? 'yes' : 'no'
@rwz
Copy link
Author

rwz commented Feb 8, 2012

I prefer first syntax cause it's much more clean and compact.

@paulmillr
Copy link

+1 for second version because it's much more clear for me as for ruby novice.

@spinogrizz
Copy link

(my_object.bool_method?) ? : 'yes' : 'no'

@rwz
Copy link
Author

rwz commented Feb 8, 2012

@spinogrizz, ok, should add that too, i guess.

@n1313
Copy link

n1313 commented Feb 8, 2012

much more clean and compact

removing ONE whitespace is "much more compact" now? like, really?

@rwz
Copy link
Author

rwz commented Feb 8, 2012

@n1313, yeah, looks better and stuff.

@pzskc383
Copy link

pzskc383 commented Feb 8, 2012

second one, double question marks scare me D:

@spinogrizz
Copy link

"yes" if object.bool_value else "no"

:-P

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