Class: Iup::Timer

Inherits:
Object
  • Object
show all
Extended by:
AttributeBuilders
Includes:
CallbackSetter
Defined in:
lib/wrapped/timer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AttributeBuilders

define_attribute, define_id_attribute, define_id_readonly, define_id_writeonly, define_property_attribute, define_property_writeonly, define_readonly, define_writeonly

Methods included from CallbackSetter

#define_callback

Constructor Details

#initialize(&block) ⇒ Timer

Returns a new instance of Timer.



9
10
11
12
13
14
# File 'lib/wrapped/timer.rb', line 9

def initialize &block
  @handle = IupLib.IupTimer

  # run any provided block on instance, to set up further attributes
  self.instance_eval &block if block_given?
end

Instance Attribute Details

#handleObject (readonly)

Returns the value of attribute handle.



7
8
9
# File 'lib/wrapped/timer.rb', line 7

def handle
  @handle
end

Instance Method Details

#action_cb(callback) ⇒ Object

Called when the time is up. Return CLOSE to end application.



31
32
33
34
35
36
37
38
39
# File 'lib/wrapped/timer.rb', line 31

def action_cb callback
  unless callback.arity.zero?
    raise ArgumentError, 'action_cb must take 0 arguments'
  end
  cb = Proc.new do |ih|
    callback.call
  end
  define_callback cb, 'ACTION_CB', :plain
end

#destroyObject

must be called when Timer is finished with



17
18
19
# File 'lib/wrapped/timer.rb', line 17

def destroy
  IupLib.IupDestroy @handle
end