Class: Praxis::ConfigHash
- Inherits:
-
BasicObject
- Defined in:
- lib/praxis/config_hash.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(hash = {}, &block) ⇒ ConfigHash
Returns a new instance of ConfigHash.
12
13
14
15
|
# File 'lib/praxis/config_hash.rb', line 12
def initialize(hash = {}, &block)
@hash = hash
@block = block
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, value, *rest, &block) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/praxis/config_hash.rb', line 26
def method_missing(name, value, *rest, &block)
if (existing = @hash[name])
if block
existing << [value, block]
else
existing << value
rest.each do |v|
existing << v
end
end
else
@hash[name] = if rest.any?
[value] + rest
else
value
end
end
end
|
Instance Attribute Details
#hash ⇒ Object
Returns the value of attribute hash.
6
7
8
|
# File 'lib/praxis/config_hash.rb', line 6
def hash
@hash
end
|
Class Method Details
.from(hash = {}, &block) ⇒ Object
8
9
10
|
# File 'lib/praxis/config_hash.rb', line 8
def self.from(hash = {}, &block)
new(hash, &block)
end
|
Instance Method Details
#respond_to_missing?(_method_name, _include_private = false) ⇒ Boolean
22
23
24
|
# File 'lib/praxis/config_hash.rb', line 22
def respond_to_missing?(_method_name, _include_private = false)
true
end
|
#to_hash ⇒ Object
17
18
19
20
|
# File 'lib/praxis/config_hash.rb', line 17
def to_hash
instance_eval(&@block)
@hash
end
|