Class: MagnumPI::DSL
- Inherits:
-
BasicObject
- Defined in:
- lib/magnum-pi/dsl.rb
Instance Method Summary
collapse
Constructor Details
#initialize(*valid_keys, &block) ⇒ DSL
Returns a new instance of DSL.
4
5
6
7
|
# File 'lib/magnum-pi/dsl.rb', line 4
def initialize(*valid_keys, &block)
@valid_keys = valid_keys.collect &:to_sym
instance_eval &block if ::Kernel.block_given?
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
53
54
55
|
# File 'lib/magnum-pi/dsl.rb', line 53
def method_missing(name, *args, &block)
process_value name, args, block
end
|
Instance Method Details
#[](name) ⇒ Object
13
14
15
|
# File 'lib/magnum-pi/dsl.rb', line 13
def [](name)
_values[name]
end
|
#class ⇒ Object
9
10
11
|
# File 'lib/magnum-pi/dsl.rb', line 9
def class
(class << self; self end).superclass
end
|
#deep_clone ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/magnum-pi/dsl.rb', line 33
def deep_clone
clone = self.class.new
valid_keys = @valid_keys.deep_clone if @valid_keys
values = @values.deep_clone if @values
clone.instance_eval do
@valid_keys = valid_keys
@values = values
end
clone
end
|
#inspect ⇒ Object
21
22
23
|
# File 'lib/magnum-pi/dsl.rb', line 21
def inspect
_values.inspect
end
|
#slice(*keys) ⇒ Object
17
18
19
|
# File 'lib/magnum-pi/dsl.rb', line 17
def slice(*keys)
_values.slice *keys
end
|
#to_hash ⇒ Object
25
26
27
|
# File 'lib/magnum-pi/dsl.rb', line 25
def to_hash
_values.to_hash
end
|
#to_s ⇒ Object
29
30
31
|
# File 'lib/magnum-pi/dsl.rb', line 29
def to_s
_values.to_s
end
|