Skip to content

Instantly share code, notes, and snippets.

@alindeman
Created October 8, 2012 17:20
Show Gist options
  • Save alindeman/3853712 to your computer and use it in GitHub Desktop.
Save alindeman/3853712 to your computer and use it in GitHub Desktop.
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"
@alindeman
Copy link
Author

1? is not a valid method name, while one? is?

@iamvery
Copy link

iamvery commented Oct 8, 2012

I always thought method names had to begin with either a lowercase letter or underscore. http://rubylearning.com/satishtalim/ruby_names.html

@caius
Copy link

caius commented Oct 8, 2012

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