Returning a value in a function in Ruby

Standard

Interesting Ruby Tidbit –
In functions, the last value is always implicitly returned.
In the function below, “a” gets returned even though there is no explicit statement stating it should be returned:

def twoplustwo
a=0
a= 2+2
a # same as  return a
end

Advertisements

One thought on “Returning a value in a function in Ruby

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