Module: Scruffy::Helpers::PointContainer
- Defined in:
- lib/scruffy/helpers/point_container.rb
Overview
Scruffy::Helpers::PointContainer
- Author
-
Mat Schaffer
- Date
-
March 22nd, 2007
Allows all standard point operations to be called on both Array and Hash
Defined Under Namespace
Class Method Summary collapse
Instance Method Summary collapse
- #inject_with_index(memo) ⇒ Object
- #maximum_value ⇒ Object
- #minimum_value ⇒ Object
- #sortable_values ⇒ Object
- #sum ⇒ Object
- #summable_values ⇒ Object
Class Method Details
.extended(point_set) ⇒ Object
10 11 12 |
# File 'lib/scruffy/helpers/point_container.rb', line 10 def self.extended point_set point_set.extend(const_get(point_set.class.to_s)) end |
Instance Method Details
#inject_with_index(memo) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/scruffy/helpers/point_container.rb', line 34 def inject_with_index memo index = 0 inject(memo) do |memo, item| ret = yield memo, item, index index = index.succ ret end end |
#maximum_value ⇒ Object
22 23 24 |
# File 'lib/scruffy/helpers/point_container.rb', line 22 def maximum_value sortable_values.sort.last end |
#minimum_value ⇒ Object
26 27 28 |
# File 'lib/scruffy/helpers/point_container.rb', line 26 def minimum_value sortable_values.sort.first end |
#sortable_values ⇒ Object
14 15 16 |
# File 'lib/scruffy/helpers/point_container.rb', line 14 def sortable_values values.find_all { |v| v.respond_to? :<=> } end |
#sum ⇒ Object
30 31 32 |
# File 'lib/scruffy/helpers/point_container.rb', line 30 def sum summable_values.inject(0) { |sum, i| sum += i } end |
#summable_values ⇒ Object
18 19 20 |
# File 'lib/scruffy/helpers/point_container.rb', line 18 def summable_values values.find_all { |v| v.respond_to? :+ } end |