문제

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