Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/everythingrb/core/array.rb

Instance Method Summary collapse

Instance Method Details

#join_map(join_with = "") {|Object| ... } ⇒ String

Combines filter_map and join operations

Examples:

[1, 2, nil, 3].join_map(" ") { |n| n&.to_s if n&.odd? }
# => "1 3"
[1, 2, nil, 3].join_map(", ")
# => "1, 2, 3"

Parameters:

  • join_with (String) (defaults to: "")

    The delimiter to join elements with (defaults to empty string)

Yields:

  • (Object)

    Block that filters and transforms array elements

Returns:

  • (String)

    Joined string of filtered and transformed elements



21
22
23
24
25
# File 'lib/everythingrb/core/array.rb', line 21

def join_map(join_with = "", &block)
  block = ->(i) { i } if block.nil?

  filter_map(&block).join(join_with)
end