Created
October 8, 2012 17:20
-
-
Save alindeman/3853712 to your computer and use it in GitHub Desktop.
This file contains 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
1.9.3p194 :001 > 1==1?"one":"not one" | |
=> "one" | |
1.9.3p194 :002 > def one | |
1.9.3p194 :003?> 1 | |
1.9.3p194 :004?> end | |
=> nil | |
1.9.3p194 :005 > 1==one?"one":"not one" | |
SyntaxError: (irb):5: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '(' | |
1==one?"one":"not one" | |
1.9.3p194 :006 > 1==one ? "one":"not one" | |
=> "one" |
I always thought method names had to begin with either a lowercase letter or underscore. http://rubylearning.com/satishtalim/ruby_names.html
I'd rewrite it as a (blah if foo) || bar
to show it in a terser form. In which case yes, it would look to be because 1?
isn't a method name, but one?
could be.
("one" if 1==one?) || "not one" # =>
# ~> -:7:in `<main>': undefined method `one?' for main:Object (NoMethodError)
("one" if 1==one) || "not one" # => "one"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1?
is not a valid method name, whileone?
is?