Class: Smalruby::EventHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/smalruby/event_handler.rb

Overview

イベントハンドラを表現するクラス

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, options, &block) ⇒ EventHandler

Returns a new instance of EventHandler.

Parameters:

  • object (Object)

    操作対象

  • options (Array)

    イベントハンドラのオプション

  • block (Proc)

    イベントハンドラ



12
13
14
15
16
17
# File 'lib/smalruby/event_handler.rb', line 12

def initialize(object, options, &block)
  @object = object
  @options = options
  @block = block
  @running = false
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



7
8
9
# File 'lib/smalruby/event_handler.rb', line 7

def block
  @block
end

#objectObject

Returns the value of attribute object.



5
6
7
# File 'lib/smalruby/event_handler.rb', line 5

def object
  @object
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/smalruby/event_handler.rb', line 6

def options
  @options
end

Instance Method Details

#call(*args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/smalruby/event_handler.rb', line 19

def call(*args)
  return nil if @running
  return Thread.start(@object, @block) { |object, block|
    begin
      @running = true
      object.instance_exec(*args, &block)
    ensure
      @running = false
    end
  }
end