Module: Infix
- Defined in:
- lib/infix.rb,
lib/infix/version.rb
Overview
Infix: Include this module to configure your classes
Constant Summary
collapse
- VERSION =
"0.1.0"
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key, val = nil, &block) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/infix.rb', line 17
def method_missing(key, val = nil, &block)
if block_given?
@nest << key
instance_eval(&block)
@nest.pop
elsif @nest.empty?
@infix[key] = val
else
nested(@infix, @nest, 0, key, val)
end
end
|
Instance Method Details
#infix(&block) ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/infix.rb', line 7
def infix(&block)
return @infix ||= {} unless block_given?
@infix ||= {}
@nest = []
instance_eval(&block)
end
|
#nested(tree, nest, idx, key, val) ⇒ Object
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/infix.rb', line 29
def nested(tree, nest, idx, key, val)
if idx == (nest.size - 1)
tree[nest[idx]] ||= {}
tree[nest[idx]][key] = val
return tree[nest[idx]]
end
tree[nest[idx]] ||= {}
nested(tree[nest[idx]], nest, idx + 1, key, val)
end
|
#respond_to_missing?(name, include_private) ⇒ Boolean
15
|
# File 'lib/infix.rb', line 15
def respond_to_missing?(name, include_private); end
|