Passing functions as arguments

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://flosspick.org - finding the right open source

formatmethod = Df.method(:datestr2time)

yes. but you don't need to, simply store the name of the method and use
'send':

   harp:~ > cat a.rb
   table =
    [%r/:BEGIN:(.*)/, "DTSTART", "datestr2time"],
    [%r/:DUE:(.*)/, "DUE", "datestr2time"]

···

On Mon, 16 Jan 2006, Alex Polite 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 = [
       [/:BEGIN:(.*)/, "DTSTART", Df.datestr2time ],
       [/:DUE:(.*)/, "DUE", Df.datestr2time]
      ]

   #
   # mock-up
   #
   class Df
     def self::datestr2time string
       p string
     end
   end

   txt = <<-txt
     :BEGIN:
     :DUE:
   txt

   txt.each do |line|
     table.each do |dispatch|
       pat, string, method = dispatch
       if pat.match line
         Df::send method, string
       end
     end
   end

   harp:~ > ruby a.rb
   "DTSTART"
   "DUE"

regards.

-a
--
strong and healthy, who thinks of sickness until it strikes like lightning?
preoccupied with the world, who thinks of death, until it arrives like
thunder? -- milarepa