Every expression in Ruby evaluates to an object

An expression in Ruby can be thought of as a line of code and the return value of every expression is an object. The IRB REPL (read-eval-print-loop) is an ideal environment for demonstrating that every Ruby expression evaluates to an object as the return value is printed after every statement. Here are some examples:

>> 5 == 5
=> true
>> x = "Bob"
=> "Bob"
>> puts "hi" if nil
=> nil
>> 1 + 2
=> 3

The return values in the example expressions return true, “Bob”, nil, and 3, all of which are objects.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s