Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7638111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:05:41+00:00 2026-05-31T08:05:41+00:00

I am puzzled that Ruby 1.9 (JRuby 1.6.6 (RUBY_VERSION == 1.9.2) and Ruby 1.9.3-p125)

  • 0

I am puzzled that Ruby 1.9 (JRuby 1.6.6 (RUBY_VERSION == “1.9.2”) and Ruby 1.9.3-p125) give a syntax error for puts(true and false).

I don’t know why – what is the problem here? How would I write that piece of code correctly? puts(true && false) works but is there a solution with and?

Example irb session:

1.9.3p125 :001 > puts(true and false)
SyntaxError: (irb):1: syntax error, unexpected keyword_and, expecting ')'
puts(true and false)
             ^
    from /home/fr/.rvm/rubies/ruby-1.9.3-p125/bin/irb:16:in `<main>'
1.9.3p125 :002 > puts(true && false)
false
 => nil 

Thanks to Mladen Jablanović for simplifying the example. The old example was f(true and f(false)).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:05:43+00:00Added an answer on May 31, 2026 at 8:05 am

    The operator precedence in ruby is && before = before and. So in your example using and, it would try to make this (implicit) assignment:

    puts(true 
    

    and then combine it with

    false)
    

    via and, which causes the syntax error. See a great explanation here: Difference between "and" and && in Ruby?

    EDIT: I’m not sure if my “implicit assignment” makes sense – think of this statement to make it explicit:

    foo = puts(true and false)
    

    EDIT 2: Remember that a method call is really called on an object. So the equivalent statements for the two cases would be:

    Object.send("puts", true && false) # this works
    Object.send("puts", true and false) # this is a syntax error
    Object.send("puts", (true and false)) # works again
    

    Not sure if that helps any more – you’re right, it’s a bit counter-intuitive. My solution is to stay away from and 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am puzzled by an error that came out of the blue yesterday on
I am puzzled. I looked at the trace of a pagecall that was slow
I was kinda puzzled by seeing that most hosting plans do offer, say, 12.000
I have this funny issue. I know this error message is found in a
I'm puzzled by this notation that did spread a lot after the first templating
I am puzzled with the statement that IE does not support <q> tag but
This question has puzzled me for a while. A public property that can be
I'm a bit puzzled with a particular regex that is seemingly simple. The match
I'm puzzled as to why using a default inclusion of jackson that Spring seems
I am completely puzzled. I was so sure that .NET shuts the whole application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.