Class: Financial::Costs
- Inherits:
-
Array
- Object
- Array
- Financial::Costs
show all
- Defined in:
- lib/financial/costs.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/financial/costs.rb', line 17
def method_missing(meth, *args, &blk)
unless args.empty?
cost = Cost.new(meth, args)
self.push(cost)
cost
else
raise CostWithoutValue, "Cost: #{meth} don't have a value. Pass a value!"
end
end
|
Instance Method Details
#parcels(number) ⇒ Object
3
4
5
6
7
|
# File 'lib/financial/costs.rb', line 3
def parcels(number)
parcels = Parcels.new(number)
self.push(parcels)
parcels
end
|
#replace_parcels_with_costs! ⇒ Object
9
10
11
12
13
14
15
|
# File 'lib/financial/costs.rb', line 9
def replace_parcels_with_costs!
costs = self.select { |cost| cost.is_a?(Parcels) }.collect do |parcels|
self.delete(parcels)
parcels.to_cost
end
costs.flatten.each { |cost| self.push(cost) }
end
|