Class: ArrayWrapper
- Inherits:
-
Object
show all
- Includes:
- FromHash
- Defined in:
- lib/formula_eval/wrapper.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &b) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/formula_eval/wrapper.rb', line 88
def method_missing(sym,*args,&b)
res = if obj.respond_to?(sym)
obj.send(sym,*args,&b).to_wrapped
elsif sym.to_s =~ /_arrayindex_(\d+)/
self[$1.to_i]
elsif obj.contains_all_hashes?
hash_mm(sym)
else
obj.send(sym,*args,&b).to_wrapped
end
res
end
|
Instance Attribute Details
Returns the value of attribute obj.
83
84
85
|
# File 'lib/formula_eval/wrapper.rb', line 83
def obj
@obj
end
|
Instance Method Details
104
105
106
|
# File 'lib/formula_eval/wrapper.rb', line 104
def *(arg)
map { |x| x * arg }
end
|
100
101
102
103
|
# File 'lib/formula_eval/wrapper.rb', line 100
def [](i)
raise "tried to pass string #{i} to array [] #{inspect}" unless i.kind_of?(Fixnum)
obj[i].to_wrapped
end
|
#hash_mm(sym) ⇒ Object
85
86
87
|
# File 'lib/formula_eval/wrapper.rb', line 85
def hash_mm(sym)
map { |h| h[sym.to_s] }.select { |x| x }.flatten.to_wrapped
end
|
#kind_of?(x) ⇒ Boolean
113
114
115
116
|
# File 'lib/formula_eval/wrapper.rb', line 113
def kind_of?(x)
return true if x == Array
super
end
|
#to_unwrapped ⇒ Object
110
111
112
|
# File 'lib/formula_eval/wrapper.rb', line 110
def to_unwrapped
obj.to_unwrapped
end
|
#to_wrapped ⇒ Object
107
108
109
|
# File 'lib/formula_eval/wrapper.rb', line 107
def to_wrapped
self
end
|