Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have a medhod like this.
def run loop do sleep 0.1 # do something end end
And I want to write it like this.
def run every 100, :msec do # do something end end
How can I write a method like this every?
every
def every(quantity, units = :sec) # this could be improved but you get the idea quantity = quantity / 1000.0 if units == :msec loop do sleep quantity yield end end every 100, :msec do puts Time.now end
Add a comment
sleep quantity; yield
loop
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.