Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/everythingrb/core/array.rb
Instance Method Summary collapse
-
#deep_freeze ⇒ self
Recursively freezes self and all of its contents.
-
#dig_map(*keys) ⇒ Array
Maps over hash keys to extract nested values using dig.
-
#join_map(join_with = "", with_index: false) {|element, index| ... } ⇒ String
Combines filter_map and join operations.
-
#key_map(key) ⇒ Array
Maps over hash keys to extract values for a specific key.
Instance Method Details
#deep_freeze ⇒ self
Recursively freezes self and all of its contents
80 81 82 83 |
# File 'lib/everythingrb/core/array.rb', line 80 def deep_freeze each { |v| v.respond_to?(:deep_freeze) ? v.deep_freeze : v.freeze } freeze end |
#dig_map(*keys) ⇒ Array
Maps over hash keys to extract nested values using dig
67 68 69 |
# File 'lib/everythingrb/core/array.rb', line 67 def dig_map(*keys) map { |v| v.dig(*keys) } end |
#join_map(join_with = "", with_index: false) {|element, index| ... } ⇒ String
Combines filter_map and join operations
28 29 30 31 32 33 34 35 36 |
# File 'lib/everythingrb/core/array.rb', line 28 def join_map(join_with = "", with_index: false, &block) block = ->(i) { i } if block.nil? if with_index filter_map.with_index(&block).join(join_with) else filter_map(&block).join(join_with) end end |
#key_map(key) ⇒ Array
Maps over hash keys to extract values for a specific key
49 50 51 |
# File 'lib/everythingrb/core/array.rb', line 49 def key_map(key) map { |v| v[key] } end |