Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/bblib/core/util/array.rb,
lib/bblib/core/hash_path/hash_path.rb
Overview
Monkey Patches
Instance Method Summary collapse
-
#bridge(*paths) ⇒ Object
Add a hash path to a hash.
-
#diff(ary) ⇒ Object
Displays all elements between this hash and another hash that are different.
- #hash_path(*path) ⇒ Object (also: #hpath)
- #hash_path_copy(*paths) ⇒ Object (also: #hpath_copy)
- #hash_path_copy_to(to, *paths) ⇒ Object (also: #hpath_copy_to)
- #hash_path_delete(*paths) ⇒ Object (also: #hpath_delete)
- #hash_path_for(value) ⇒ Object (also: #hpath_for)
- #hash_path_move(*paths) ⇒ Object (also: #hpath_move)
- #hash_path_move_to(to, *paths) ⇒ Object (also: #hpath_move_to)
- #hash_path_set(*paths) ⇒ Object (also: #hpath_set)
- #hash_paths ⇒ Object (also: #hpaths)
- #hmap ⇒ Object
- #interleave(ary) ⇒ Object
-
#join_terms(seperator = :and, delimiter: ', ', encapsulate: nil) ⇒ Object
Conventient way to join an array into a comma seperated list with the last two elements seperated by a word like ‘and’ or ‘or’.
-
#keys_to_s ⇒ Object
Converts all keys in nested hashes to strings.
-
#keys_to_sym(clean: false) ⇒ Object
Converts all keys in nested hashes to symbols.
-
#msplit(*delims) ⇒ Object
(also: #multi_split)
Splits all elements in an array using a list of delimiters.
-
#to_tree_hash ⇒ Object
Creates a tree hash wrapper for this array.
Instance Method Details
#bridge(*paths) ⇒ Object
Add a hash path to a hash
205 206 207 |
# File 'lib/bblib/core/hash_path/hash_path.rb', line 205 def bridge(*paths) replace(to_tree_hash.bridge(*paths)) end |
#diff(ary) ⇒ Object
Displays all elements between this hash and another hash that are different.
66 67 68 |
# File 'lib/bblib/core/util/array.rb', line 66 def diff(ary) (self - ary) + (ary - self) end |
#hash_path(*path) ⇒ Object Also known as: hpath
158 159 160 |
# File 'lib/bblib/core/hash_path/hash_path.rb', line 158 def hash_path(*path) BBLib.hash_path(self, *path) end |
#hash_path_copy(*paths) ⇒ Object Also known as: hpath_copy
166 167 168 |
# File 'lib/bblib/core/hash_path/hash_path.rb', line 166 def hash_path_copy(*paths) BBLib.hash_path_copy(self, *paths) end |
#hash_path_copy_to(to, *paths) ⇒ Object Also known as: hpath_copy_to
170 171 172 |
# 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 |
#hash_path_delete(*paths) ⇒ Object Also known as: hpath_delete
174 175 176 |
# File 'lib/bblib/core/hash_path/hash_path.rb', line 174 def hash_path_delete(*paths) BBLib.hash_path_delete(self, *paths) end |
#hash_path_for(value) ⇒ Object Also known as: hpath_for
190 191 192 |
# File 'lib/bblib/core/hash_path/hash_path.rb', line 190 def hash_path_for(value) BBLib.hash_path_key_for(self, value) end |
#hash_path_move(*paths) ⇒ Object Also known as: hpath_move
178 179 180 |
# File 'lib/bblib/core/hash_path/hash_path.rb', line 178 def hash_path_move(*paths) BBLib.hash_path_move(self, *paths) end |
#hash_path_move_to(to, *paths) ⇒ Object Also known as: hpath_move_to
182 183 184 |
# 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 |
#hash_path_set(*paths) ⇒ Object Also known as: hpath_set
162 163 164 |
# File 'lib/bblib/core/hash_path/hash_path.rb', line 162 def hash_path_set(*paths) BBLib.hash_path_set(self, *paths) end |
#hash_paths ⇒ Object Also known as: hpaths
186 187 188 |
# File 'lib/bblib/core/hash_path/hash_path.rb', line 186 def hash_paths BBLib.hash_path_keys(self) end |
#hmap ⇒ Object
88 89 90 91 |
# File 'lib/bblib/core/util/array.rb', line 88 def hmap return map unless block_given? map { |v| yield(v) }.compact.to_h end |
#interleave(ary) ⇒ Object
60 61 62 |
# File 'lib/bblib/core/util/array.rb', line 60 def interleave(ary) BBLib.interleave(self, ary) end |
#join_terms(seperator = :and, delimiter: ', ', encapsulate: nil) ⇒ Object
Conventient way to join an array into a comma seperated list with the last two elements seperated by a word like ‘and’ or ‘or’.
81 82 83 84 85 86 |
# 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 ⇒ Object
Converts all keys in nested hashes to strings.
54 55 56 |
# 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) ⇒ Object
Converts all keys in nested hashes to symbols.
49 50 51 |
# 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) ⇒ Object Also known as: multi_split
Splits all elements in an array using a list of delimiters.
42 43 44 |
# File 'lib/bblib/core/util/array.rb', line 42 def msplit(*delims) map { |elem| elem.msplit(*delims) if elem.respond_to?(:msplit) }.flatten end |