Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/flazm_ruby_helpers/data_structures.rb
Overview
Adding transversal logic
Instance Method Summary collapse
- #to_yaml_inline(pad_left_indents: 0, indent_size: 2) ⇒ Object
- #walk_keys(kproc) ⇒ Object
-
#walk_values(vproc) ⇒ Object
rubocop:disable Style/ClassAndModuleChildren.
Instance Method Details
#to_yaml_inline(pad_left_indents: 0, indent_size: 2) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/flazm_ruby_helpers/data_structures.rb', line 20 def to_yaml_inline(pad_left_indents: 0, indent_size: 2) indent_string = ' ' * indent_size pad_indent = indent_string * pad_left_indents result = JSON.parse(to_json).to_yaml(indentation: indent_size, line_width: -1).to_str.lines.to_a[1..-1].collect \ { |line| pad_indent + line } result.join end |
#walk_keys(kproc) ⇒ Object
14 15 16 17 18 |
# File 'lib/flazm_ruby_helpers/data_structures.rb', line 14 def walk_keys(kproc) map do |array_item| array_item.is_a?(Hash) || array_item.is_a?(Array) ? array_item.walk_keys(kproc) : array_item end end |
#walk_values(vproc) ⇒ Object
rubocop:disable Style/ClassAndModuleChildren
8 9 10 11 12 |
# File 'lib/flazm_ruby_helpers/data_structures.rb', line 8 def walk_values(vproc) map do |array_item| array_item.is_a?(Hash) || array_item.is_a?(Array) ? array_item.walk_values(vproc) : vproc.call(array_item) end end |