Class: GoogleMaps::Services::ArrayBox
- Inherits:
-
Object
- Object
- GoogleMaps::Services::ArrayBox
- Defined in:
- lib/googlemaps/services/util.rb
Overview
Performs Array boxing.
Class Method Summary collapse
-
.contains_all?(arr, other) ⇒ TrueClass, FalseClass
Determines if one array contains all elements of another array.
-
.wrap(object) ⇒ Array
Wrap its argument in an array unless it is already an array or (array-like).
Class Method Details
.contains_all?(arr, other) ⇒ TrueClass, FalseClass
Determines if one array contains all elements of another array.
51 52 53 54 55 56 57 58 59 |
# File 'lib/googlemaps/services/util.rb', line 51 def self.contains_all?(arr, other) h = arr.inject(Hash.new(0)) {|h, i| h[i] += 1; h} other.each do |i| return false unless h.has_key?(i) return false if h[i].zero? h[i] -= 1 end return true end |
.wrap(object) ⇒ Array
Wrap its argument in an array unless it is already an array or (array-like).
32 33 34 35 36 37 38 39 40 |
# File 'lib/googlemaps/services/util.rb', line 32 def self.wrap(object) if object.nil? [] elsif object.respond_to? :to_ary object.to_ary || [object] else [object] end end |