RubyCocoa で繰り返しのタイマーを使うサンプルです。
require 'osx/foundation'
include OSX
class TestTimer
def updateTimer(timer)
p Time.now
end
def setTimer
@timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats(
60, self, :updateTimer, nil, true)
end
end
p Time.now
ts = TestTimer.new
ts.setTimer
begin
CFRunLoopRun()
resucue Interrupt
end
確認バージョン
- ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin11.0]
- RubyCocoa-1.0.5-OSX10.7/10.8