Class: Dish::Plate
- Inherits:
-
Object
show all
- Defined in:
- lib/dish/plate.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(hash) ⇒ Plate
13
14
15
|
# File 'lib/dish/plate.rb', line 13
def initialize(hash)
@_original_hash = Hash[hash.map { |k, v| [k.to_s, v] }]
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/dish/plate.rb', line 17
def method_missing(method, *args, &block)
method = method.to_s
if method.end_with?("?")
key = method[0..-2]
_check_for_presence(key)
else
_get_value(method)
end
end
|
Class Method Details
.coerce(key, klass_or_proc) ⇒ Object
8
9
10
|
# File 'lib/dish/plate.rb', line 8
def coerce(key, klass_or_proc)
coercions[key.to_s] = klass_or_proc
end
|
.coercions ⇒ Object
4
5
6
|
# File 'lib/dish/plate.rb', line 4
def coercions
@coercions ||= Hash.new(Plate)
end
|
Instance Method Details
#as_hash ⇒ Object
31
32
33
|
# File 'lib/dish/plate.rb', line 31
def as_hash
@_original_hash
end
|
#respond_to_missing?(method, *args) ⇒ Boolean
27
28
29
|
# File 'lib/dish/plate.rb', line 27
def respond_to_missing?(method, *args)
_check_for_presence(method.to_s) || super
end
|