Skip to content

Instantly share code, notes, and snippets.

@flarnie
Created July 23, 2013 02:45
Show Gist options
  • Save flarnie/6059476 to your computer and use it in GitHub Desktop.
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
#@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