table_print
table_print copied to clipboard
Displaying nested arrays?
I have this:
tp [[1,2,3],[44,55,66]], :second, :last, object_class: lambda{|ary| ary.first}
which I expect something like:
| SECOND | LAST | OBJECT_CLASS |
|---|---|---|
| 2 | 3 | 1 |
| 55 | 66 | 44 |
but I get a:
NoMethodError: undefined method `first' for 1:Fixnum
from (irb):181:in `block in irb_binding'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print/fingerprinter.rb:38:in `call'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print/fingerprinter.rb:38:in `block in populate_row'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print/fingerprinter.rb:35:in `each'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print/fingerprinter.rb:35:in `populate_row'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print/fingerprinter.rb:19:in `block in hash_to_rows'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print/fingerprinter.rb:18:in `each'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print/fingerprinter.rb:18:in `hash_to_rows'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print/fingerprinter.rb:9:in `lift'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print.rb:41:in `block in table_print'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print.rb:40:in `each'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print.rb:40:in `table_print'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print.rb:73:in `tp'
If you try without the lambda, you get the improbable following:
>> tp [[1,2,3],[44,55,66]], :first, :second
FIRST | SECOND
---------------|-------
Method Missing | 1
Method Missing | 2
Method Missing | 3
Method Missing | 44
Method Missing | 55
Method Missing | 66
It would be very handy to be able to display arrays of arrays with table_print. Unfortunately, currently, it seems that tp flatten them before displaying the table.
or am I doing something wrong?
That's a bug. There's a place where I wrap the dataset with Array() that's messing it up. Unfortunately the fix is non-trivial.
Just came across this. Could you point out where this bug is?