Class: Talkgh::Entity
- Inherits:
-
Object
show all
- Includes:
- Keys
- Defined in:
- lib/talkgh/entity.rb
Instance Method Summary
collapse
Methods included from Keys
#attribute_key, #camelcase, #camelcase_key, #hyphenate, #hyphenate_key
Constructor Details
#initialize(**kwargs) ⇒ Entity
5
6
7
|
# File 'lib/talkgh/entity.rb', line 5
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/talkgh/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/talkgh/entity.rb', line 23
def ==(entity)
entity.class == self.class && entity.attributes == @attributes
end
|
#[]=(key, value) ⇒ Object
9
10
11
|
# File 'lib/talkgh/entity.rb', line 9
def []=(key, value)
@attributes[attribute_key(key)] = value
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
13
14
15
|
# File 'lib/talkgh/entity.rb', line 13
def respond_to_missing?(name, include_private = false)
@attributes.key?(name) or super
end
|
#to_h ⇒ Object
27
28
29
|
# File 'lib/talkgh/entity.rb', line 27
def to_h
@attributes
end
|