Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/geokit-rails/core_extensions.rb

Overview

Extend Array with a sort_by_distance method.

Instance Method Summary collapse

Instance Method Details

#sort_by_distance_from(origin, opts = {}) ⇒ Object

This method creates a “distance” attribute on each object, calculates the distance from the passed origin, and finally sorts the array by the resulting distance.



6
7
8
9
# File 'lib/geokit-rails/core_extensions.rb', line 6

def sort_by_distance_from(origin, opts={})
  warn "[DEPRECATION] `Array#sort_by_distance_from(origin, opts)` is deprecated. Please use Array#sort_by{|e| e.distance_to(origin, opts)} instead which is not destructive"
  self[0..-1] = sort_by{|e| e.distance_to(origin, opts)}
end