Class: Telegem::Types::BaseType

Inherits:
Object
  • Object
show all
Defined in:
lib/api/types.rb

Direct Known Subclasses

CallbackQuery, Chat, Message, MessageEntity, Update, User

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ BaseType

Returns a new instance of BaseType.



4
5
6
# File 'lib/api/types.rb', line 4

def initialize(data)
  @_raw_data = data || {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/api/types.rb', line 8

def method_missing(name, *args)
  key = name.to_s
  return @_raw_data[key] if @_raw_data.key?(key)
  
  camel_key = snake_to_camel(key)
  return @_raw_data[camel_key] if @_raw_data.key?(camel_key)
  
  super
end

Instance Attribute Details

#_raw_dataObject (readonly)

Returns the value of attribute _raw_data.



24
25
26
# File 'lib/api/types.rb', line 24

def _raw_data
  @_raw_data
end

Instance Method Details

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

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/api/types.rb', line 18

def respond_to_missing?(name, include_private = false)
  key = name.to_s
  camel_key = snake_to_camel(key)
  @_raw_data.key?(key) || @_raw_data.key?(camel_key) || super
end