class Array
Monkey Patches
Monkey Patches for the Array
class
Public Instance Methods
Add a hash path to a hash
# File lib/bblib/core/hash_path/hash_path.rb, line 205 def bridge(*paths) replace(to_tree_hash.bridge(*paths)) end
Displays all elements between this hash and another hash that are different. @param [Array] ary The ary to compare elements to.
# File lib/bblib/core/util/array.rb, line 66 def diff(ary) (self - ary) + (ary - self) end
# File lib/bblib/core/hash_path/hash_path.rb, line 158 def hash_path(*path) BBLib.hash_path(self, *path) end
# File lib/bblib/core/hash_path/hash_path.rb, line 166 def hash_path_copy(*paths) BBLib.hash_path_copy(self, *paths) end
# File lib/bblib/core/hash_path/hash_path.rb, line 170 def hash_path_copy_to(to, *paths) BBLib.hash_path_copy_to(self, to, *paths) end
# File lib/bblib/core/hash_path/hash_path.rb, line 174 def hash_path_delete(*paths) BBLib.hash_path_delete(self, *paths) end
# File lib/bblib/core/hash_path/hash_path.rb, line 190 def hash_path_for(value) BBLib.hash_path_key_for(self, value) end
# File lib/bblib/core/hash_path/hash_path.rb, line 178 def hash_path_move(*paths) BBLib.hash_path_move(self, *paths) end
# File lib/bblib/core/hash_path/hash_path.rb, line 182 def hash_path_move_to(to, *paths) BBLib.hash_path_move_to(self, to, *paths) end
# File lib/bblib/core/hash_path/hash_path.rb, line 162 def hash_path_set(*paths) BBLib.hash_path_set(self, *paths) end
# File lib/bblib/core/hash_path/hash_path.rb, line 186 def hash_paths BBLib.hash_path_keys(self) end
# File lib/bblib/core/util/array.rb, line 88 def hmap return map unless block_given? map { |v| yield(v) }.compact.to_h end
Conventient way to join an array into a comma seperated list with the last two elements seperated by a word like 'and' or 'or'. @param seperator [String] The term or phrase to seperate the last two elements by @param delimiter [String] The delimiter used in the join. This allows something other than ', ' to be used @param encapsulate [String] This will optionally encapsulate each element with a character or string. Useful to wrap all elements in quotes. @returns [String] By default returns a comma seperated list with the final elements seperated by an 'and'. Behavior can be overriden using the params.
# File lib/bblib/core/util/array.rb, line 81 def join_terms(seperator = :and, delimiter: ', ', encapsulate: nil) elements = (encapsulate ? map { |element| element.to_s.encapsulate(encapsulate) } : self) return elements.join(delimiter) if size <= 1 return elements.join(" #{seperator} ") if size == 2 [elements[0..-2].join(delimiter), elements.last].join(" #{seperator} ") end
Converts all keys in nested hashes to strings.
# File lib/bblib/core/util/array.rb, line 54 def keys_to_s map { |v| v.respond_to?(:keys_to_s) ? v.keys_to_s : v } end
Converts all keys in nested hashes to symbols.
# File lib/bblib/core/util/array.rb, line 49 def keys_to_sym(clean: false) map { |elem| elem.respond_to?(:keys_to_sym) ? elem.keys_to_sym(clean: clean) : elem } end
Splits all elements in an array using a list of delimiters.
# File lib/bblib/core/util/array.rb, line 42 def msplit(*delims) map { |elem| elem.msplit(*delims) if elem.respond_to?(:msplit) }.flatten end
Creates a tree hash wrapper for this array.
# File lib/bblib/core/util/array.rb, line 71 def to_tree_hash TreeHash.new(self) end