Watson1978
11/4/2011 - 3:03 PM

MacRuby : Sample of NSTimer

MacRuby : Sample of NSTimer

# -*- coding: utf-8 -*-
framework "Cocoa"

class AppDelegate
  def initialize
    # NSTimer の初期化
    @timer = NSTimer.scheduledTimerWithTimeInterval(1.0,
                                                    target:self,
                                                    selector:"output:",
                                                    userInfo:nil,
                                                    repeats:true)
    @count = 0
  end

  # NSTimer で定期的に呼び出されるメソッド
  def output(timer)
    puts @count
    @count += 1
  end
end


app = NSApplication.sharedApplication
app.delegate = AppDelegate.new
app.run