0

I am using a gem called "ice_cube"

When buliding a schedule i need to pass some integers into the .day() method like so:

schedule.add_recurrence_rule IceCube::Rule.weekly(1).day(1,2,3)

when i do this directly, it works. However, when i try to pass a variable that contains the integers into the .day() method is where I get lost.

tried this:

days = [1,2,3]

schedule.add_recurrence_rule IceCube::Rule.weekly(1).day(days)

it doesn't work. error i get is...

NoMethodError (undefined method `<' for [1, 2, 3]:Array):

Am i making a very obvious mistake?

How should i format my variable days so that it is accepted?

jBeas
  • 926
  • 7
  • 20

2 Answers2

4

You probably need to use the splat operator to expand the array into separate arguments (which then get combined into a single array in the days method probably):

days = [1,2,3]

schedule.add_recurrence_rule IceCube::Rule.weekly(self.every.to_i).day(*days)
Pete
  • 11,313
  • 4
  • 43
  • 54
  • Just what I was about to suggest, but shouldn't the splat be before the variable name like this: *days – Jakob W Jan 06 '12 at 21:07
  • I'll allow it :) Thank you very much. I have seen this around, mostly in rdoc's but have never paid much attention to it. You don't know something until you learn it! Thank you! – jBeas Jan 06 '12 at 21:19
  • @Pete Haha, then I wish it was friday more often for me ;-) – Jakob W Jan 07 '12 at 10:15
0
schedule.add_recurrence_rule IceCube::Rule.weekly(1).day(*days)
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • thank you for your quick response Dave. I admire the minimalism, but chose the other answer for obvious reasons. Have a nice weekend, thanks again! – jBeas Jan 06 '12 at 21:21