Created
July 23, 2013 02:45
-
-
Save flarnie/6059476 to your computer and use it in GitHub Desktop.
an example of a Class#to_s method from the minesweeper code found here: https://github.com/paradasia/minesweeper
This file contains hidden or 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
#@board and @size are defined in initialize | |
def to_s | |
final_str = "" | |
top_border = (0..(@size-1).to_a * " " | |
final_str << " | #{top_border}\n | " + "--" * @size + "\n" | |
@board.each_with_index do |line, y| | |
final_str << " #{y} | #{line.map(&:to_s).join(" ")}\n" | |
end | |
#return a string! don't 'puts' it. : ) | |
final_str | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment