Class: Nexmo::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/nexmo/entity.rb

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ Entity

Returns a new instance of Entity.



3
4
5
# File 'lib/nexmo/entity.rb', line 3

def initialize(**kwargs)
  @attributes = kwargs
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



17
18
19
20
21
# File 'lib/nexmo/entity.rb', line 17

def method_missing(name, *args)
  return super unless @attributes.key?(name)

  @attributes[name]
end

Instance Method Details

#==(entity) ⇒ Object



23
24
25
# File 'lib/nexmo/entity.rb', line 23

def ==(entity)
  entity.class == self.class && entity.attributes == @attributes
end

#[]=(key, value) ⇒ Object



7
8
9
10
11
# File 'lib/nexmo/entity.rb', line 7

def []=(key, value)
  name = self.class.attribute_names[key]

  @attributes[name] = value
end

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

Returns:

  • (Boolean)


13
14
15
# File 'lib/nexmo/entity.rb', line 13

def respond_to_missing?(name, include_private = false)
  @attributes.key?(name) or super
end

#to_hObject



27
28
29
# File 'lib/nexmo/entity.rb', line 27

def to_h
  @attributes
end