سؤال

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?

هل كانت مفيدة؟

المحلول

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)

نصائح أخرى

schedule.add_recurrence_rule IceCube::Rule.weekly(1).day(*days)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top