class Highway::Utilities

This class contains a collection of utility functions used throughout the codebase.

Public Class Methods

hash_map(subject, &transform) click to toggle source

Map pairs of keys and values and combine them again into a Hash.

@param subject [Hash] An input hash. @param transform [Proc] A transformation block.

@return [Hash]

# File lib/highway/utilities.rb, line 20
def self.hash_map(subject, &transform)
  Hash[subject.map(&transform)]
end
keypath_to_s(keypath) click to toggle source

Join keypath into a string.

@param keypath [Array<String>] A keypath.

@return [String]

# File lib/highway/utilities.rb, line 29
def self.keypath_to_s(keypath)
  keypath.join(".")
end
recursive_include?(subject, element) click to toggle source

Recursively check whether the subject includes an element.

@param subject [Object] A haystack. @param element [Object] A needle.

@return [Boolean]

# File lib/highway/utilities.rb, line 39
def self.recursive_include?(subject, element)
  if subject.is_a?(Hash)
    recursive_include?(subject.values, element)
  elsif subject.respond_to?(:any?)
    subject.any? { |value| recursive_include?(value, element) }
  else
    subject == element
  end
end