How can I have multiple lines in the ruby interactive shell?

This is an example:

2.1.2 :053 > a = 1
=> 1
2.1.2 :054 > b = 2
=> 2
2.1.2 :055 > a + b
 => 3
2.1.2 :056 > if a > b  #The code ‘if ..." starts the definition of the conditional statement. 
2.1.2 :057?>   puts "false"
2.1.2 :058?>   else
2.1.2 :059 >     puts "true"
2.1.2 :060?>   end     #The "end" tells Ruby we’re done the conditional statement.
"true"     # output
=> nil     # returned value

IRB can tell us the result of the last expression it evaluated.

You can get more useful information from here(https://www.ruby-lang.org/en/documentation/quickstart/).


One quick way to do this is to wrap the code in if true. Code will run when you close the if block.

if true
  User.where('foo > 1')
    .map { |u| u.username }
end