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: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d0618248ba09
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c3662bc663a3
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Mar 8, 2015

  1. Copy the full SHA
    464ef98 View commit details
  2. Merge pull request #2665 from bjfish/truffle_array_transpose

    [Truffle] Adding Array#transpose to array.rb.
    chrisseaton committed Mar 8, 2015
    Copy the full SHA
    c3662bc View commit details
Showing with 22 additions and 7 deletions.
  1. +0 −7 spec/truffle/tags/core/array/transpose_tags.txt
  2. +22 −0 truffle/src/main/ruby/core/rubinius/common/array.rb
7 changes: 0 additions & 7 deletions spec/truffle/tags/core/array/transpose_tags.txt

This file was deleted.

22 changes: 22 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/array.rb
Original file line number Diff line number Diff line change
@@ -419,4 +419,26 @@ def to_ary
self
end

def transpose
return [] if empty?

out = []
max = nil

each do |ary|
ary = Rubinius::Type.coerce_to ary, Array, :to_ary
max ||= ary.size

# Catches too-large as well as too-small (for which #fetch would suffice)
raise IndexError, "All arrays must be same length" if ary.size != max

ary.size.times do |i|
entry = (out[i] ||= [])
entry << ary.at(i)
end
end

out
end

end