Permalink
Browse files

Transposing a table returns a new table

  • Loading branch information...
1 parent 53baea1 commit 911f08f88afdd534cd21f35be08ae2dd88a607b7 @davelyon committed Feb 15, 2012
Showing with 5 additions and 7 deletions.
  1. +3 −4 lib/turnip/table.rb
  2. +2 −3 spec/table_spec.rb
View
@@ -22,13 +22,12 @@ def hashes
end
def rows_hash
- transpose!
- hashes.first
+ transpose.hashes.first
end
- def transpose!
+ def transpose
raise %{The table must have exactly #{width} columns} unless width == 2
- @raw = raw.transpose
+ @raw = self.class.new(raw.transpose)
end
def each
View
@@ -45,8 +45,7 @@
let(:raw) { [["Name", "Dave"], ["Age", "99"], ["Height", "6ft"]] }
it 'transposes the raw table' do
- table.transpose!
- table.hashes.should == [{ "Name" => "Dave", "Age" => "99", "Height" => "6ft" }]
+ table.transpose.hashes.should == [{ "Name" => "Dave", "Age" => "99", "Height" => "6ft" }]
end
end
@@ -55,7 +54,7 @@
let(:raw) { [["a", "b", "c"], ["1", "2", "3"]] }
it 'raises an error' do
- expect { table.transpose! }.to raise_error
+ expect { table.transpose }.to raise_error
end
end
end

0 comments on commit 911f08f

Please sign in to comment.