[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Newbie question- Return method

James Schoonmaker

10/1/2008 12:33:00 PM

I'm trying to teach myself the basics of Ruby (based on the guide at
http://pine.fm/Lear...), and I ran across the Return method. I'm
not clear on what it does and how it works, though, and all of the
searches I made for it didn't address the method itself.

Any help?
--
Posted via http://www.ruby-....

14 Answers

Patrick Doyle

10/1/2008 12:54:00 PM

0

The word "return" is a reserved word in ruby, just like the words
"def", "if", "while", etc...

"return" is used in a method to exit the method and to return the
given value to the caller. In principal, you could write

def compute_square(x)
return x*x
end

...although The Ruby Way(tm) would be to simply write:

def compute_square(x)
x*x
end

since, by the definition of the language, the return value of a method
is (99.99% of the time) the last expression computed in the method.

--wpd


On Wed, Oct 1, 2008 at 8:33 AM, James Schoonmaker
<james.schoonmaker@gmail.com> wrote:
> I'm trying to teach myself the basics of Ruby (based on the guide at
> http://pine.fm/Lear...), and I ran across the Return method. I'm
> not clear on what it does and how it works, though, and all of the
> searches I made for it didn't address the method itself.
>
> Any help?
> --
> Posted via http://www.ruby-....
>
>

Lloyd Linklater

10/1/2008 1:05:00 PM

0

Patrick Doyle wrote:
> The word "return" is a reserved word in ruby, just like the words
> "def", "if", "while", etc...
>
> "return" is used in a method to exit the method and to return the
> given value to the caller. In principal, you could write
>
> def compute_square(x)
> return x*x
> end
>
> ...although The Ruby Way(tm) would be to simply write:
>
> def compute_square(x)
> x*x
> end
>
> since, by the definition of the language, the return value of a method
> is (99.99% of the time) the last expression computed in the method.
>

You can use it to pick what you want returned if it is not the last
thing in the method.

e.g.

def myMethod s
d = 'foo'
s.upcase!
end

p myMethod("hiya")

=> "HIYA"

However

def myMethod s
d = "foo"
s.upcase!
return d
end

p myMethod("hiya")

=> "foo"

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

Sebastian Hungerecker

10/1/2008 2:44:00 PM

0

Lloyd Linklater wrote:
> def myMethod s
> =C2=A0 d =3D 'foo'
> =C2=A0 s.upcase!
> end
>
> p myMethod("hiya")
>
> =3D> =C2=A0"HIYA"
>
> However
>
> def myMethod s
> =C2=A0 d =3D "foo"
> =C2=A0 s.upcase!
> =C2=A0 return d
> end
>
> p myMethod("hiya")

Yes, but:
def myMethod s
d =3D "foo"
s.upcase!
d
end
p myMethod("hiya")

Does the same without return.

=2D-=20
Jabber: sepp2k@jabber.org
ICQ: 205544826

Lloyd Linklater

10/1/2008 7:00:00 PM

0

Sebastian Hungerecker wrote:
> Lloyd Linklater wrote:
>>
>> def myMethod s
>>   d = "foo"
>>   s.upcase!
>>   return d
>> end
>>
>> p myMethod("hiya")
>
> Yes, but:
> def myMethod s
> d = "foo"
> s.upcase!
> d
> end
> p myMethod("hiya")
>
> Does the same without return.

While that is true, I wanted to keep it to the point for this thread. I
did refer to it when I said,

> Lloyd Linklater wrote:
>>
>> You can use it to pick what you want returned if it is not the last
>> thing in the method.
--
Posted via http://www.ruby-....

Redshirt Bluejacket

2/21/2012 9:17:00 PM

0

On Feb 21, 12:38 am, Ja...@nospam.com (Jason) wrote:
> In article
> <5df47b03-f51f-4996-bd19-2fcb9c4d2...@t15g2000yqi.googlegroups.com>,
>
>
>
>
>
> Redshirt Bluejacket <knujonmap...@hotmail.com> wrote:

> > > Related to the possibility that bears evolved into whales.
>
> > Give me a few million years and I'll evolve bears into whales --
> > entirely by selecting whichever offspring from one generation to the
> > next express random mutations most coincidental with movement towards
> > whaledom. I'll grant that nature would likely take a few dozen
> > millions of years longer than I would, but that's time it had.... btw
> > before you ask, I'm not an atheist, but a Pandeist, -- and,Pandeism,
> > you see proposes a Creator which actually possesses sufficient power
> > and intelligence to set forth a Universe where complex and varied life
> > (and indeed, intelligent life, as our own) is able to arise from
> > nothing more than the operation of the carefully crafted laws of
> > physics through processes such as chemical abiogenesis and evolution
> > by natural selection. It's a bit beyond what the theistic gods are
> > claimed to have been able to pull off.
>
> I doubt that you could make that happen since bears are VERY different
> than whales.- Hide quoted text -
>
> - Show quoted text -

That is why it would take a few million years. But not much longer
than that. Remember, it only took a few thousand years -- in the
course of recorded human history in fact -- for wolf-dogs howling on
the plains to evolve into the whole range of dogs, from chihuahuas and
weiner dogs to great danes and St Bernards, and everything in between.
I'm sure you know some dogs are, by breeding, excellent swimmers.
Given just a few thousand years more, you or I could take one of those
breeds and make it a primarily acquatic mammal. If breeding (or
circumstances) selected for acquatic affiliation and size, we'd have
some pretty big marine mammals before long!!

And how different exactly do you think bears are from whales? They
have generally the same bones, muscles, and internal organs, the main
things differing being the length and thickness of the bones and
muscles (which has been shown to be aptly breedable), and some
comparatively minor distribution of organs. They are made of all the
same proteins, use the same metabolic structures to turn food into
energy, even share some of the same evolutionary foibles such as the
uselessly descending vagus nerve.

Jason

2/21/2012 9:41:00 PM

0

In article
<3a8b629f-5adb-44d8-a1e2-49a56d0c86ba@do4g2000vbb.googlegroups.com>,
Redshirt Bluejacket <knujonmapson@hotmail.com> wrote:

> On Feb 21, 12:38=A0am, Ja...@nospam.com (Jason) wrote:
> > In article
> > <5df47b03-f51f-4996-bd19-2fcb9c4d2...@t15g2000yqi.googlegroups.com>,
> >
> >
> >
> >
> >
> > Redshirt Bluejacket <knujonmap...@hotmail.com> wrote:
>
> > > > Related to the possibility that bears evolved into whales.
> >
> > > Give me a few million years and I'll evolve bears into whales --
> > > entirely by selecting whichever offspring from one generation to the
> > > next express random mutations most coincidental with movement towards
> > > whaledom. I'll grant that nature would likely take a few dozen
> > > millions of years longer than I would, but that's time it had.... btw
> > > before you ask, I'm not an atheist, but a Pandeist, -- and,Pandeism,
> > > you see proposes a Creator which actually possesses sufficient power
> > > and intelligence to set forth a Universe where complex and varied life
> > > (and indeed, intelligent life, as our own) is able to arise from
> > > nothing more than the operation of the carefully crafted laws of
> > > physics through processes such as chemical abiogenesis and evolution
> > > by natural selection. It's a bit beyond what the theistic gods are
> > > claimed to have been able to pull off.
> >
> > I doubt that you could make that happen since bears are VERY different
> > than whales.- Hide quoted text -
> >
> > - Show quoted text -
>
> That is why it would take a few million years. But not much longer
> than that. Remember, it only took a few thousand years -- in the
> course of recorded human history in fact -- for wolf-dogs howling on
> the plains to evolve into the whole range of dogs, from chihuahuas and
> weiner dogs to great danes and St Bernards, and everything in between.
> I'm sure you know some dogs are, by breeding, excellent swimmers.
> Given just a few thousand years more, you or I could take one of those
> breeds and make it a primarily acquatic mammal. If breeding (or
> circumstances) selected for acquatic affiliation and size, we'd have
> some pretty big marine mammals before long!!
>
> And how different exactly do you think bears are from whales? They
> have generally the same bones, muscles, and internal organs, the main
> things differing being the length and thickness of the bones and
> muscles (which has been shown to be aptly breedable), and some
> comparatively minor distribution of organs. They are made of all the
> same proteins, use the same metabolic structures to turn food into
> energy, even share some of the same evolutionary foibles such as the
> uselessly descending vagus nerve.

Perhaps you would have more success with hippos or rhinos.

However, I doubt that you would succeed. There are vast differences
between whales and bears--hippos and rhinos.


Redshirt Bluejacket

2/22/2012 5:26:00 AM

0

On Feb 21, 4:40 pm, Ja...@nospam.com (Jason) wrote:
> In article
> <3a8b629f-5adb-44d8-a1e2-49a56d0c8...@do4g2000vbb.googlegroups.com>,
>
>
> Redshirt Bluejacket <knujonmap...@hotmail.com> wrote:
> > On Feb 21, 12:38=A0am, Ja...@nospam.com (Jason) wrote:
> > > In article
> > > <5df47b03-f51f-4996-bd19-2fcb9c4d2...@t15g2000yqi.googlegroups.com>,
>
> > > Redshirt Bluejacket <knujonmap...@hotmail.com> wrote:
>
> > > > > Related to the possibility that bears evolved into whales.
>
> > > > Give me a few million years and I'll evolve bears into whales --
> > > > entirely by selecting whichever offspring from one generation to the
> > > > next express random mutations most coincidental with movement towards
> > > > whaledom. I'll grant that nature would likely take a few dozen
> > > > millions of years longer than I would, but that's time it had.... btw
> > > > before you ask, I'm not an atheist, but a Pandeist, -- and,Pandeism,
> > > > you see proposes a Creator which actually possesses sufficient power
> > > > and intelligence to set forth a Universe where complex and varied life
> > > > (and indeed, intelligent life, as our own) is able to arise from
> > > > nothing more than the operation of the carefully crafted laws of
> > > > physics through processes such as chemical abiogenesis and evolution
> > > > by natural selection. It's a bit beyond what the theistic gods are
> > > > claimed to have been able to pull off.
>
> > > I doubt that you could make that happen since bears are VERY different
> > > than whales.- Hide quoted text -
>
> > > - Show quoted text -
>
> > That is why it would take a few million years. But not much longer
> > than that. Remember, it only took a few thousand years -- in the
> > course of recorded human history in fact -- for wolf-dogs howling on
> > the plains to evolve into the whole range of dogs, from chihuahuas and
> > weiner dogs to great danes and St Bernards, and everything in between.
> > I'm sure you know some dogs are, by breeding, excellent swimmers.
> > Given just a few thousand years more, you or I could take one of those
> > breeds and make it a primarily acquatic mammal. If breeding (or
> > circumstances) selected for acquatic affiliation and size, we'd have
> > some pretty big marine mammals before long!!
>
> > And how different exactly do you think bears are from whales? They
> > have generally the same bones, muscles, and internal organs, the main
> > things differing being the length and thickness of the bones and
> > muscles (which has been shown to be aptly breedable), and some
> > comparatively minor distribution of organs. They are made of all the
> > same proteins, use the same metabolic structures to turn food into
> > energy, even share some of the same evolutionary foibles such as the
> > uselessly descending vagus nerve.
>
> Perhaps you would have more success with hippos or rhinos.
>
> However, I doubt that you would succeed. There are vast differences
> between whales and bears--hippos and rhinos.

How many generations do you suppose it would take to evolve a bear
into a very big otter, then?

How many generations from that big otter to a comparably sized seal?

From a seal to something fully aquatic like a manatee?

From a manatee to a small whale?

From a small whale to a medium sized one, like a killer whale-size?

From a killer-whale size to a great whale? (actually once you have
'whale' at all size is simply a matter of scaling up)....

Jason

2/22/2012 9:18:00 AM

0

In article
<481a0a52-d831-4bf1-a4eb-700ebaa7214b@a15g2000yqf.googlegroups.com>,
Redshirt Bluejacket <knujonmapson@hotmail.com> wrote:

> On Feb 21, 4:40=A0pm, Ja...@nospam.com (Jason) wrote:
> > In article
> > <3a8b629f-5adb-44d8-a1e2-49a56d0c8...@do4g2000vbb.googlegroups.com>,
> >
> >
> > Redshirt Bluejacket <knujonmap...@hotmail.com> wrote:
> > > On Feb 21, 12:38=3DA0am, Ja...@nospam.com (Jason) wrote:
> > > > In article
> > > > <5df47b03-f51f-4996-bd19-2fcb9c4d2...@t15g2000yqi.googlegroups.com>,
> >
> > > > Redshirt Bluejacket <knujonmap...@hotmail.com> wrote:
> >
> > > > > > Related to the possibility that bears evolved into whales.
> >
> > > > > Give me a few million years and I'll evolve bears into whales --
> > > > > entirely by selecting whichever offspring from one generation to th=
> e
> > > > > next express random mutations most coincidental with movement towar=
> ds
> > > > > whaledom. I'll grant that nature would likely take a few dozen
> > > > > millions of years longer than I would, but that's time it had.... b=
> tw
> > > > > before you ask, I'm not an atheist, but a Pandeist, -- and,Pandeism=
> ,
> > > > > you see proposes a Creator which actually possesses sufficient powe=
> r
> > > > > and intelligence to set forth a Universe where complex and varied l=
> ife
> > > > > (and indeed, intelligent life, as our own) is able to arise from
> > > > > nothing more than the operation of the carefully crafted laws of
> > > > > physics through processes such as chemical abiogenesis and evolutio=
> n
> > > > > by natural selection. It's a bit beyond what the theistic gods are
> > > > > claimed to have been able to pull off.
> >
> > > > I doubt that you could make that happen since bears are VERY differen=
> t
> > > > than whales.- Hide quoted text -
> >
> > > > - Show quoted text -
> >
> > > That is why it would take a few million years. But not much longer
> > > than that. Remember, it only took a few thousand years -- in the
> > > course of recorded human history in fact -- for wolf-dogs howling on
> > > the plains to evolve into the whole range of dogs, from chihuahuas and
> > > weiner dogs to great danes and St Bernards, and everything in between.
> > > I'm sure you know some dogs are, by breeding, excellent swimmers.
> > > Given just a few thousand years more, you or I could take one of those
> > > breeds and make it a primarily acquatic mammal. If breeding (or
> > > circumstances) selected for acquatic affiliation and size, we'd have
> > > some pretty big marine mammals before long!!
> >
> > > And how different exactly do you think bears are from whales? They
> > > have generally the same bones, muscles, and internal organs, the main
> > > things differing being the length and thickness of the bones and
> > > muscles (which has been shown to be aptly breedable), and some
> > > comparatively minor distribution of organs. They are made of all the
> > > same proteins, use the same metabolic structures to turn food into
> > > energy, even share some of the same evolutionary foibles such as the
> > > uselessly descending vagus nerve.
> >
> > Perhaps you would have more success with hippos or rhinos.
> >
> > However, I doubt that you would succeed. There are vast differences
> > between whales and bears--hippos and rhinos.
>
> How many generations do you suppose it would take to evolve a bear
> into a very big otter, then?
>
> How many generations from that big otter to a comparably sized seal?
>
> From a seal to something fully aquatic like a manatee?
>
> From a manatee to a small whale?
>
> From a small whale to a medium sized one, like a killer whale-size?
>
> From a killer-whale size to a great whale? (actually once you have
> 'whale' at all size is simply a matter of scaling up)....

You can believe all of the above. I believe that God created whales.


Wombat

2/22/2012 10:41:00 AM

0

On Feb 22, 10:18 am, Ja...@nospam.com (Jason) wrote:
> In article
> <481a0a52-d831-4bf1-a4eb-700ebaa72...@a15g2000yqf.googlegroups.com>,
>
>
>
>
>
>
>
>
>
> Redshirt Bluejacket <knujonmap...@hotmail.com> wrote:
> > On Feb 21, 4:40=A0pm, Ja...@nospam.com (Jason) wrote:
> > > In article
> > > <3a8b629f-5adb-44d8-a1e2-49a56d0c8...@do4g2000vbb.googlegroups.com>,
>
> > > Redshirt Bluejacket <knujonmap...@hotmail.com> wrote:
> > > > On Feb 21, 12:38=3DA0am, Ja...@nospam.com (Jason) wrote:
> > > > > In article
> > > > > <5df47b03-f51f-4996-bd19-2fcb9c4d2...@t15g2000yqi.googlegroups.com>,
>
> > > > > Redshirt Bluejacket <knujonmap...@hotmail.com> wrote:
>
> > > > > > > Related to the possibility that bears evolved into whales.
>
> > > > > > Give me a few million years and I'll evolve bears into whales --
> > > > > > entirely by selecting whichever offspring from one generation to th=
> > e
> > > > > > next express random mutations most coincidental with movement towar=
> > ds
> > > > > > whaledom. I'll grant that nature would likely take a few dozen
> > > > > > millions of years longer than I would, but that's time it had..... b=
> > tw
> > > > > > before you ask, I'm not an atheist, but a Pandeist, -- and,Pandeism=
> > ,
> > > > > > you see proposes a Creator which actually possesses sufficient powe=
> > r
> > > > > > and intelligence to set forth a Universe where complex and varied l=
> > ife
> > > > > > (and indeed, intelligent life, as our own) is able to arise from
> > > > > > nothing more than the operation of the carefully crafted laws of
> > > > > > physics through processes such as chemical abiogenesis and evolutio=
> > n
> > > > > > by natural selection. It's a bit beyond what the theistic gods are
> > > > > > claimed to have been able to pull off.
>
> > > > > I doubt that you could make that happen since bears are VERY differen=
> > t
> > > > > than whales.- Hide quoted text -
>
> > > > > - Show quoted text -
>
> > > > That is why it would take a few million years. But not much longer
> > > > than that. Remember, it only took a few thousand years -- in the
> > > > course of recorded human history in fact -- for wolf-dogs howling on
> > > > the plains to evolve into the whole range of dogs, from chihuahuas and
> > > > weiner dogs to great danes and St Bernards, and everything in between.
> > > > I'm sure you know some dogs are, by breeding, excellent swimmers.
> > > > Given just a few thousand years more, you or I could take one of those
> > > > breeds and make it a primarily acquatic mammal. If breeding (or
> > > > circumstances) selected for acquatic affiliation and size, we'd have
> > > > some pretty big marine mammals before long!!
>
> > > > And how different exactly do you think bears are from whales? They
> > > > have generally the same bones, muscles, and internal organs, the main
> > > > things differing being the length and thickness of the bones and
> > > > muscles (which has been shown to be aptly breedable), and some
> > > > comparatively minor distribution of organs. They are made of all the
> > > > same proteins, use the same metabolic structures to turn food into
> > > > energy, even share some of the same evolutionary foibles such as the
> > > > uselessly descending vagus nerve.
>
> > > Perhaps you would have more success with hippos or rhinos.
>
> > > However, I doubt that you would succeed. There are vast differences
> > > between whales and bears--hippos and rhinos.
>
> > How many generations do you suppose it would take to evolve a bear
> > into a very big otter, then?
>
> > How many generations from that big otter to a comparably sized seal?
>
> > From a seal to something fully aquatic like a manatee?
>
> > From a manatee to a small whale?
>
> > From a small whale to a medium sized one, like a killer whale-size?
>
> > From a killer-whale size to a great whale? (actually once you have
> > 'whale' at all size is simply a matter of scaling up)....
>
> You can believe all of the above. I believe that God created whales.

Does that include durodon and Zeuglodon?

Mitchell Holman

2/22/2012 1:35:00 PM

0

Jason@nospam.com (Jason) wrote in
news:Jason-2202120118110001@67-150-122-116.lsan.mdsg-pacwest.com:

> In article
> <481a0a52-d831-4bf1-a4eb-700ebaa7214b@a15g2000yqf.googlegroups.com>,
> Redshirt Bluejacket <knujonmapson@hotmail.com> wrote:
>
>> On Feb 21, 4:40=A0pm, Ja...@nospam.com (Jason) wrote:
>> > In article
>> > <3a8b629f-5adb-44d8-a1e2-49a56d0c8...@do4g2000vbb.googlegroups.com>,
>> >
>> >
>> > Redshirt Bluejacket <knujonmap...@hotmail.com> wrote:
>> > > On Feb 21, 12:38=3DA0am, Ja...@nospam.com (Jason) wrote:
>> > > > In article
>> > > > <5df47b03-f51f-4996-bd19-2fcb9c4d2...@t15g2000yqi.googlegroups.c
>> > > > om>,
>> >
>> > > > Redshirt Bluejacket <knujonmap...@hotmail.com> wrote:
>> >
>> > > > > > Related to the possibility that bears evolved into whales.
>> >
>> > > > > Give me a few million years and I'll evolve bears into whales
>> > > > > -- entirely by selecting whichever offspring from one
>> > > > > generation to th=
>> e
>> > > > > next express random mutations most coincidental with movement
>> > > > > towar=
>> ds
>> > > > > whaledom. I'll grant that nature would likely take a few
>> > > > > dozen millions of years longer than I would, but that's time
>> > > > > it had.... b=
>> tw
>> > > > > before you ask, I'm not an atheist, but a Pandeist, --
>> > > > > and,Pandeism=
>> ,
>> > > > > you see proposes a Creator which actually possesses
>> > > > > sufficient powe=
>> r
>> > > > > and intelligence to set forth a Universe where complex and
>> > > > > varied l=
>> ife
>> > > > > (and indeed, intelligent life, as our own) is able to arise
>> > > > > from nothing more than the operation of the carefully crafted
>> > > > > laws of physics through processes such as chemical
>> > > > > abiogenesis and evolutio=
>> n
>> > > > > by natural selection. It's a bit beyond what the theistic
>> > > > > gods are claimed to have been able to pull off.
>> >
>> > > > I doubt that you could make that happen since bears are VERY
>> > > > differen=
>> t
>> > > > than whales.- Hide quoted text -
>> >
>> > > > - Show quoted text -
>> >
>> > > That is why it would take a few million years. But not much
>> > > longer than that. Remember, it only took a few thousand years --
>> > > in the course of recorded human history in fact -- for wolf-dogs
>> > > howling on the plains to evolve into the whole range of dogs,
>> > > from chihuahuas and weiner dogs to great danes and St Bernards,
>> > > and everything in between. I'm sure you know some dogs are, by
>> > > breeding, excellent swimmers. Given just a few thousand years
>> > > more, you or I could take one of those breeds and make it a
>> > > primarily acquatic mammal. If breeding (or circumstances)
>> > > selected for acquatic affiliation and size, we'd have some pretty
>> > > big marine mammals before long!!
>> >
>> > > And how different exactly do you think bears are from whales?
>> > > They have generally the same bones, muscles, and internal organs,
>> > > the main things differing being the length and thickness of the
>> > > bones and muscles (which has been shown to be aptly breedable),
>> > > and some comparatively minor distribution of organs. They are
>> > > made of all the same proteins, use the same metabolic structures
>> > > to turn food into energy, even share some of the same
>> > > evolutionary foibles such as the uselessly descending vagus
>> > > nerve.
>> >
>> > Perhaps you would have more success with hippos or rhinos.
>> >
>> > However, I doubt that you would succeed. There are vast differences
>> > between whales and bears--hippos and rhinos.
>>
>> How many generations do you suppose it would take to evolve a bear
>> into a very big otter, then?
>>
>> How many generations from that big otter to a comparably sized seal?
>>
>> From a seal to something fully aquatic like a manatee?
>>
>> From a manatee to a small whale?
>>
>> From a small whale to a medium sized one, like a killer whale-size?
>>
>> From a killer-whale size to a great whale? (actually once you have
>> 'whale' at all size is simply a matter of scaling up)....
>
> You can believe all of the above. I believe that God created whales.


Did he also create all the transitional species
in between wolves and whales?

Or did he just pepper the rock strata with their
fossils as some sort of cosmic joke?


http://en.wikipedia.org/wiki/Evolution_of...