Class: FinerStruct::Immutable
- Inherits:
-
Object
- Object
- FinerStruct::Immutable
show all
- Defined in:
- lib/finer_struct/immutable.rb
Instance Method Summary
collapse
Constructor Details
#initialize(attributes = {}) ⇒ Immutable
Returns a new instance of Immutable.
6
7
8
9
|
# File 'lib/finer_struct/immutable.rb', line 6
def initialize(attributes = {})
@attributes = attributes.dup.freeze
freeze
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments) ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/finer_struct/immutable.rb', line 11
def method_missing(method, *arguments)
if @attributes.has_key?(method)
@attributes[method]
else
super
end
end
|
Instance Method Details
#respond_to?(method) ⇒ Boolean
19
20
21
|
# File 'lib/finer_struct/immutable.rb', line 19
def respond_to?(method)
@attributes.has_key?(method) || super
end
|
#to_hash ⇒ Object
23
24
25
|
# File 'lib/finer_struct/immutable.rb', line 23
def to_hash
@attributes
end
|