Skip to content

Instantly share code, notes, and snippets.

@tanatana
Created October 15, 2012 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanatana/3891233 to your computer and use it in GitHub Desktop.
Save tanatana/3891233 to your computer and use it in GitHub Desktop.
RubyのMatrixの拡張 []= と to_s
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