Module: NMatrixExtensions
- Defined in:
- lib/nmatrix_extensions.rb
Instance Method Summary collapse
Instance Method Details
#pretty_string(opts = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/nmatrix_extensions.rb', line 8 def pretty_string(opts={}) { :col_header => nil, :row_header => nil }.merge!(opts) ("%-3s" % "#") + opts[:col_header].inject("") { |s, a| s + ("%7s" % a) } + "\n" + self.to_a.map_with_index { |a, i| ("%-3s" % opts[:row_header][i]) + a.inject("") { |s, v| if v.is_a? Float s + ("%7.2f" % v) else s + ("%7d" % v) end } }.join("\n") end |