class Array

Monkey Patches

Monkey Patches for the Array class

Public Instance Methods

bridge(*paths) click to toggle source

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
diff(ary) click to toggle source

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
hash_path(*path) click to toggle source
# File lib/bblib/core/hash_path/hash_path.rb, line 158
def hash_path(*path)
  BBLib.hash_path(self, *path)
end
Also aliased as: hpath
hash_path_copy(*paths) click to toggle source
# File lib/bblib/core/hash_path/hash_path.rb, line 166
def hash_path_copy(*paths)
  BBLib.hash_path_copy(self, *paths)
end
Also aliased as: hpath_copy
hash_path_copy_to(to, *paths) click to toggle source
# 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
Also aliased as: hpath_copy_to
hash_path_delete(*paths) click to toggle source
# File lib/bblib/core/hash_path/hash_path.rb, line 174
def hash_path_delete(*paths)
  BBLib.hash_path_delete(self, *paths)
end
Also aliased as: hpath_delete
hash_path_for(value) click to toggle source
# File lib/bblib/core/hash_path/hash_path.rb, line 190
def hash_path_for(value)
  BBLib.hash_path_key_for(self, value)
end
Also aliased as: hpath_for
hash_path_move(*paths) click to toggle source
# File lib/bblib/core/hash_path/hash_path.rb, line 178
def hash_path_move(*paths)
  BBLib.hash_path_move(self, *paths)
end
Also aliased as: hpath_move
hash_path_move_to(to, *paths) click to toggle source
# 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
Also aliased as: hpath_move_to
hash_path_set(*paths) click to toggle source
# File lib/bblib/core/hash_path/hash_path.rb, line 162
def hash_path_set(*paths)
  BBLib.hash_path_set(self, *paths)
end
Also aliased as: hpath_set
hash_paths() click to toggle source
# File lib/bblib/core/hash_path/hash_path.rb, line 186
def hash_paths
  BBLib.hash_path_keys(self)
end
Also aliased as: hpaths
hmap() { |v| ... } click to toggle source
# File lib/bblib/core/util/array.rb, line 88
def hmap
  return map unless block_given?
  map { |v| yield(v) }.compact.to_h
end
hpath(*path)
Alias for: hash_path
hpath_copy(*paths)
Alias for: hash_path_copy
hpath_copy_to(to, *paths)
Alias for: hash_path_copy_to
hpath_delete(*paths)
Alias for: hash_path_delete
hpath_for(value)
Alias for: hash_path_for
hpath_move(*paths)
Alias for: hash_path_move
hpath_move_to(to, *paths)
Alias for: hash_path_move_to
hpath_set(*paths)
Alias for: hash_path_set
hpaths()
Alias for: hash_paths
interleave(ary) click to toggle source

Takes two arrays (can be of different length) and interleaves them like [a, b, a, b…]

# File lib/bblib/core/util/array.rb, line 60
def interleave(ary)
  BBLib.interleave(self, ary)
end
join_terms(seperator = :and, delimiter: ', ', encapsulate: nil) click to toggle source

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
keys_to_s() click to toggle source

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
keys_to_sym(clean: false) click to toggle source

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
msplit(*delims) click to toggle source

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
Also aliased as: multi_split
multi_split(*delims)
Alias for: msplit
to_tree_hash() click to toggle source

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