Domanda

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?

È stato utile?

Soluzione

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)

Altri suggerimenti

schedule.add_recurrence_rule IceCube::Rule.weekly(1).day(*days)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top