Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/full_join/core_ext/array/full_join.rb
Overview
extension original class
Instance Method Summary collapse
-
#full_join(other, &block) ⇒ Array
Returns a new array full joined other.
Instance Method Details
#full_join(other, &block) ⇒ Array
Returns a new array full joined other.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/full_join/core_ext/array/full_join.rb', line 38 def full_join(other, &block) block = ->(s) { s } unless block_given? results = each_with_object([]) do |obj1, arr| found = false other.each do |obj2| next unless block.call(obj1) == block.call(obj2) arr << [obj1, obj2] found = true break end arr << [obj1, nil] unless found end results.concat((other - results.map(&:last)).zip([]).map(&:reverse)) end |