Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #3040

Re: Understanding the return method

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!feeds.phibee-telecom.net!talisker.lacave.net!lacave.net!not-for-mail
From jake kaiden <jakekaiden@yahoo.com>
Newsgroups comp.lang.ruby
Subject Re: Understanding the return method
Date Sat, 16 Apr 2011 18:28:47 -0500
Organization Service de news de lacave.net
Lines 29
Message-ID <c5a3ade58d4bf73465e9098ab1d430ba@ruby-forum.com> (permalink)
References <4aa6da7c8d4c99589c8a48a80c677218@ruby-forum.com>
NNTP-Posting-Host bristol.highgroove.com
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Trace talisker.lacave.net 1302996546 19626 65.111.164.187 (16 Apr 2011 23:29:06 GMT)
X-Complaints-To abuse@lacave.net
NNTP-Posting-Date Sat, 16 Apr 2011 23:29:06 +0000 (UTC)
In-Reply-To <4aa6da7c8d4c99589c8a48a80c677218@ruby-forum.com>
X-Received-From This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway
X-Mail-Count 381731
X-Ml-Name ruby-talk
X-Rubymirror Yes
X-Ruby-Talk <c5a3ade58d4bf73465e9098ab1d430ba@ruby-forum.com>
Xref x330-a1.tempe.blueboxinc.net comp.lang.ruby:3040

Show key headers only | View raw


hey fily -

  i'm not the best person to answer this question (as i'm really 
something of a newb myself,) but i'll get you started...

  every method in ruby returns a value (even if it is nil, thus all the 
=>nil's in irb.)  by default, the value that a method returns is the 
LAST statement evaluated - which is something to be aware of.

  note that for the example you have shown this works just as well:

def multiply(val1, val2 )
  val1 * val2
end

value = multiply( 10, 20 )
puts value

#=> 200

  while there are really times when you want to use 'return,' (which 
surely someone else can better explain,) generally speaking, the last 
statement evaluated in your method is what is returned.

  -j

-- 
Posted via http://www.ruby-forum.com/.

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Understanding the return method Fily Salas <fs_tigre@hotmail.com> - 2011-04-16 17:41 -0500
  Re: Understanding the return method Iñaki Baz Castillo <ibc@aliax.net> - 2011-04-16 18:00 -0500
  Re: Understanding the return method Vincent Manis <vmanis@telus.net> - 2011-04-16 18:25 -0500
  Re: Understanding the return method jake kaiden <jakekaiden@yahoo.com> - 2011-04-16 18:28 -0500
  Re: Understanding the return method jake kaiden <jakekaiden@yahoo.com> - 2011-04-16 18:35 -0500
    Re: Understanding the return method 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-16 22:10 -0500
      Re: Understanding the return method Vincent Manis <vmanis@telus.net> - 2011-04-17 00:09 -0500
      Re: Understanding the return method Iñaki Baz Castillo <ibc@aliax.net> - 2011-04-17 09:41 -0500
  Re: Understanding the return method Fily Salas <fs_tigre@hotmail.com> - 2011-04-16 21:05 -0500
  Re: Understanding the return method Fily Salas <fs_tigre@hotmail.com> - 2011-04-17 07:19 -0500

csiph-web