Skip to content

Instantly share code, notes, and snippets.

@practicingruby
Created August 28, 2012 17:29
Show Gist options
  • Select an option

  • Save practicingruby/3501154 to your computer and use it in GitHub Desktop.

Select an option

Save practicingruby/3501154 to your computer and use it in GitHub Desktop.
class FormattedTable
def initialize(table)
@table = table
end
def to_s
@table.map { |row| row.join(" | ") }.join("\n")
end
end
class Table
include Enumerable
def initialize
@data = [[1,2,3],[4,5,6],[7,8,9]]
end
def each
@data.each { |e| yield(e) }
end
end
puts FormattedTable.new(Table.new)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment