Class: RBGL::GUI::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/rbgl/gui/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, **data) ⇒ Event

Returns a new instance of Event.



8
9
10
11
# File 'lib/rbgl/gui/event.rb', line 8

def initialize(type, **data)
  @type = type
  @data = data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



17
18
19
# File 'lib/rbgl/gui/event.rb', line 17

def method_missing(name, *args)
  @data.key?(name) ? @data[name] : super
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/rbgl/gui/event.rb', line 6

def data
  @data
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/rbgl/gui/event.rb', line 6

def type
  @type
end

Instance Method Details

#[](key) ⇒ Object



13
14
15
# File 'lib/rbgl/gui/event.rb', line 13

def [](key)
  @data[key]
end

#inspectObject



29
30
31
# File 'lib/rbgl/gui/event.rb', line 29

def inspect
  "Event[#{@type}, #{@data.map { |k, v| "#{k}: #{v}" }.join(', ')}]"
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/rbgl/gui/event.rb', line 21

def respond_to_missing?(name, include_private = false)
  @data.key?(name) || super
end

#to_hObject



25
26
27
# File 'lib/rbgl/gui/event.rb', line 25

def to_h
  { type: @type }.merge(@data)
end