[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Passing a method call into a method

Glenn

9/16/2008 7:14:00 PM

Hi,=0A=0AThanks for the help with my question.=A0 All three solutions are g=
reat.=0A=0ASorry I wasn't more clear describing the problem.=A0 I'll try to=
be more clear when I ask another question in the future.=0A=0AI have to ad=
mit that I don't think I understand the method below.=A0 I tried it out and=
see that it works, but don't necessarily see how it works yet.=A0 I will l=
ook at it some more.=0A=0AThanks again,=0A=0AGlenn=0A=0A=0A=0A----- Origina=
l Message ----=0AFrom: William James <w_a_x_man@yahoo.com>=0ATo: ruby-talk =
ML <ruby-talk@ruby-lang.org>=0ASent: Sunday, September 14, 2008 4:02:54 PM=
=0ASubject: Re: Passing a method call into a method=0A=0AOn Sep 14, 8:18 am=
, Glenn <glenn_r...@yahoo.com> wrote:=0A> [Note:=A0 parts of this message w=
ere removed to make it a legal post.]=0A>=0A> Hi,=0A>=0A> I am trying to fi=
gure out how to pass a method call into a method.=0A>=0A> I wrote a generic=
method that call be called on an array of numbers, and returns an array of=
the index values in the receiver that meet a specified condition:=0A>=0A> =
class Array=0A>=A0 def hash_of_indexes=0A>=A0 =A0 if self.empty?=0A>=A0 =A0=
=A0 'The array is empty.'=0A>=A0 =A0 else=0A>=A0 =A0 =A0 h =3D {}=0A>=A0 =
=A0 =A0 self.each_with_index { |e, i| h.include?(e.to_f) ? h[e.to_f] << i :=
h[e.to_f] =3D [i] }=0A>=A0 =A0 =A0 h=0A>=A0 =A0 end=0A>=A0 end=0A=0A=0Acla=
ss Array=0A=A0 def hash_of_indexes=0A=A0 =A0 h =3D {}=0A=A0 =A0 each_with_i=
ndex{ |e,i|=0A=A0 =A0 =A0 e =3D e.to_f=0A=A0 =A0 =A0 h[e] =3D Array( h[e] )=
<< i }=0A=A0 =A0 h=0A=A0 end=0Aend