Class: Highway::Utilities
- Inherits:
-
Object
- Object
- Highway::Utilities
- Defined in:
- lib/highway/utilities.rb
Overview
This class contains a collection of utility functions used throughout the codebase.
Class Method Summary collapse
-
.hash_map(subject, &transform) ⇒ Hash
Map pairs of keys and values and combine them again into a Hash.
-
.keypath_to_s(keypath) ⇒ String
Join keypath into a string.
-
.recursive_include?(subject, element) ⇒ Boolean
Recursively check whether the subject includes an element.
Class Method Details
.hash_map(subject, &transform) ⇒ Hash
Map pairs of keys and values and combine them again into a Hash.
20 21 22 |
# File 'lib/highway/utilities.rb', line 20 def self.hash_map(subject, &transform) Hash[subject.map(&transform)] end |
.keypath_to_s(keypath) ⇒ String
Join keypath into a string.
29 30 31 |
# File 'lib/highway/utilities.rb', line 29 def self.keypath_to_s(keypath) keypath.join(".") end |
.recursive_include?(subject, element) ⇒ Boolean
Recursively check whether the subject includes an element.
39 40 41 42 43 44 45 46 47 |
# 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 |