Created
January 30, 2011 15:51
-
-
Save ericgj/802961 to your computer and use it in GitHub Desktop.
A non-destructive implementation of Table#select_columns that creates a new table (note this is not tested)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Table | |
def max_y | |
@rows[0].length | |
end | |
def select_columns | |
selected = (0..(max_y - 1)).map do |i| | |
col = @rows.map {|row| row[i] } | |
col if yield(col) | |
end.compact.transpose | |
if @header_support | |
self.class.new [@headers] << selected, :headers => true | |
else | |
self.class.new selected, :headers => false | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment