Module: CoreExt::Enumerable

Defined in:
lib/core_ext/enumerable.rb

Instance Method Summary collapse

Instance Method Details

#as_hObject



9
10
11
# File 'lib/core_ext/enumerable.rb', line 9

def as_h
  map(&:as_h)
end

#as_sObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/core_ext/enumerable.rb', line 13

def as_s
  return "[]" if empty?

  map { |k| "  #{k.as_s}" }
    .intersperse(",")
    .each_slice(2)
    .map(&:join)
    .prepend("[")
    .append("]")
    .join("\n")
end

#intersperse(value) ⇒ Object



5
6
7
# File 'lib/core_ext/enumerable.rb', line 5

def intersperse(value)
  flat_map { |h| [h, value] }.tap(&:pop)
end