Class: Telegem::Types::BaseType

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ BaseType

Returns a new instance of BaseType.



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

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



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

def method_missing(name, *args)
  return super if args.any? || block_given?
  
  define_accessor(name)
  
  if respond_to?(name)
    send(name)
  else
    super
  end
end

Instance Attribute Details

#_raw_dataObject (readonly)

Returns the value of attribute _raw_data.



41
42
43
# File 'lib/api/types.rb', line 41

def _raw_data
  @_raw_data
end

Instance Method Details

#inspectObject



33
34
35
# File 'lib/api/types.rb', line 33

def inspect
  "#<#{self.class.name} #{@_raw_data.inspect}>"
end

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

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/api/types.rb', line 21

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

#to_hObject Also known as: to_hash



27
28
29
# File 'lib/api/types.rb', line 27

def to_h
  @_raw_data.dup
end

#to_sObject



37
38
39
# File 'lib/api/types.rb', line 37

def to_s
  inspect
end