Created
October 15, 2012 07:38
-
-
Save tanatana/3891233 to your computer and use it in GitHub Desktop.
RubyのMatrixの拡張 []= と to_s
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 Matrix | |
# m[i,j] = x | |
def []=(i,j,x) | |
@rows[i][j]=x | |
end | |
# m.to_s | |
def to_s(separator = ", ") | |
str = '' | |
self.row_size.times do |i| | |
str << self.row(i).to_a.join("#{separator}") + "\n" | |
end | |
return str | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment