Class: Smalruby3::EventHandler

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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



7
8
9
10
11
12
# File 'lib/smalruby3/event_handler.rb', line 7

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

Instance Attribute Details

#blockObject

Returns the value of attribute block.



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

def block
  @block
end

#objectObject

Returns the value of attribute object.



3
4
5
# File 'lib/smalruby3/event_handler.rb', line 3

def object
  @object
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/smalruby3/event_handler.rb', line 4

def options
  @options
end

Instance Method Details

#call(*args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/smalruby3/event_handler.rb', line 14

def call(*args)
  if @running
    return nil
  end

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