class GoogleMaps::Services::ArrayBox
Performs Array boxing.
Public Class Methods
contains_all?(arr, other)
click to toggle source
Determines if one array contains all elements of another array.
@param [Array] arr target array. @param [Array] other array to look for in the target array. @example
myarr = ["hello", "world"] ArrayBox.contains_all? myarr, ["hello"] # true
@return [TrueClass, FalseClass] a boolean.
# 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)
click to toggle source
Wrap its argument in an array unless it is already an array or (array-like).
@param [Object] object Object to wrap. @example Wrap any Object in a array
ArrayBox.wrap(nil) # [] ArrayBox.wrap([1, 2, 3]) # [1, 2, 3] ArrayBox.wrap(1) # [1]
@return [Array] an array.
# 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