[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Passing functions as arguments

alex

1/15/2006 9:39:00 PM

I'm just starting out with ruby.

I'm trying to make an array of arrays containing [a pattern, a string,
a function]

Patterns and strings went fine but when I put in a function ruby tries
to eval it and complains about not getting right number of arguments.

Is there any way to escape a method so that you can put it in a list
or pass it as an argument to another function?

pats = [
[/:BEGIN:(.*)/, "DTSTART", Df.datestr2time ],
[/:DUE:(.*)/, "DUE", Df.datestr2time]
]


alex

--
Alex Polite
http://flo... - finding the right open source


3 Answers

ptkwt

1/15/2006 10:11:00 PM

0

In article <ad9751290601151338k1384454fj64b900831961a4f6@mail.gmail.com>,
Alex Polite <notmyprivateemail@gmail.com> wrote:
>I'm just starting out with ruby.
>
>I'm trying to make an array of arrays containing [a pattern, a string,
>a function]
>
>Patterns and strings went fine but when I put in a function ruby tries
>to eval it and complains about not getting right number of arguments.
>
>Is there any way to escape a method so that you can put it in a list
>or pass it as an argument to another function?
>
>pats =3D [
> [/:BEGIN:(.*)/, "DTSTART", Df.datestr2time ],
> [/:DUE:(.*)/, "DUE", Df.datestr2time]
> ]
>

How about:

pats = [
[/:BEGIN:(.*)/, "DRSTART", Df.method(:datestr2time)],
[/:DUE:(.*)/, "DUE", Df.method(:datestr2time)]
]



Phil

Ara.T.Howard

1/16/2006 12:54:00 AM

0

Timothy Goddard

1/18/2006 11:17:00 AM

0

'send' is _much_ slower than 'method.call'. The first example is
probably the clearest and most efficient way to do this, especially in
a high-use function.