Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d608aff44e36
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b6139e652067
Choose a head ref
  • 3 commits
  • 2 files changed
  • 2 contributors

Commits on Dec 22, 2014

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2b5b513 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1a40288 View commit details
  3. Merge pull request #3250 from sferik/flat_map_multi_yield

    Fix bug in flat_map for enumerables that yield multiple values
    jc00ke committed Dec 22, 2014

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b6139e6 View commit details
Showing with 13 additions and 3 deletions.
  1. +4 −3 kernel/common/enumerable.rb
  2. +9 −0 spec/ruby/core/enumerable/shared/collect_concat.rb
7 changes: 4 additions & 3 deletions kernel/common/enumerable.rb
Original file line number Diff line number Diff line change
@@ -90,11 +90,12 @@ def each_with_object(memo)
def flat_map
return to_enum(:flat_map) unless block_given?

inject([]) do |a, e|
result = yield e

a = []
each do |*args|
result = yield(*args)
Rubinius::Type.object_respond_to_ary?(result) ? a.concat(result) : a.push(result)
end
a
end

alias_method :collect_concat, :flat_map
9 changes: 9 additions & 0 deletions spec/ruby/core/enumerable/shared/collect_concat.rb
Original file line number Diff line number Diff line change
@@ -19,6 +19,15 @@
numerous.send(@method){ |i| i }.should == [:foo, obj2]
end

it "only returns the first value when multiple values are yielded" do
obj = Object.new
def obj.each
yield(1, 2)
end
obj.extend(Enumerable)
obj.send(@method){ |i| i }.should == [1]
end

it "returns an enumerator when no block given" do
enum = EnumerableSpecs::Numerous.new(1, 2).send(@method)
enum.should be_an_instance_of(enumerator_class)