在fxri中不能pp(漂亮的打印)? (红宝石)

时间:2010-07-30 09:03:11

标签: ruby

这是来自fxri的一点复制/粘贴。为什么会发生这种情况,我该如何解决? Ruby版本是;在64位Windows 7上 ruby​​ 1.8.6(2008-08-11 patchlevel 287)[i386-mswin32]

irb(main):334:0> pp "a"
NoMethodError: undefined method `<<' for #<FXIrb:0x6229524>
from ..../Ruby/lib/ruby/1.8/prettyprint.rb:146:in `text'
from ..../Ruby/lib/ruby/1.8/prettyprint.rb:198:in `group'
from ..../Ruby/lib/ruby/1.8/pp.rb:140:in `pp'
from ..../Ruby/lib/ruby/1.8/PP.rb:77:in `pp'
from ..../Ruby/lib/ruby/1.8/pp.rb:119:in `guard_inspect_key'
from ..../Ruby/lib/ruby/1.8/PP.rb:77:in `pp'
from ..../Ruby/lib/ruby/1.8/PP.rb:60:in `pp'
from ..../Ruby/lib/ruby/1.8/PP.rb:59:in `each'
from ..../Ruby/lib/ruby/1.8/PP.rb:59:in `pp'
from (irb):334
from :0

irb(main):335:0> a = {'a', 'b', 'c', 'd'}
=> {"a"=>"b", "c"=>"d"}
irb(main):336:0> a
=> {"a"=>"b", "c"=>"d"}
irb(main):337:0> pp a
NoMethodError: undefined method `<<' for #<FXIrb:0x6229524>
from ..../Ruby/lib/ruby/1.8/prettyprint.rb:146:in `text'
from ..../Ruby/lib/ruby/1.8/prettyprint.rb:198:in `group'
from ..../Ruby/lib/ruby/1.8/pp.rb:140:in `pp'
from ..../Ruby/lib/ruby/1.8/PP.rb:77:in `pp'
from ..../Ruby/lib/ruby/1.8/pp.rb:119:in `guard_inspect_key'
from ..../Ruby/lib/ruby/1.8/PP.rb:77:in `pp'
from ..../Ruby/lib/ruby/1.8/PP.rb:60:in `pp'
from ..../Ruby/lib/ruby/1.8/PP.rb:59:in `each'
from ..../Ruby/lib/ruby/1.8/PP.rb:59:in `pp'
from (irb):337
from :0

irb(main):338:0> ary = Array.new(5) {|i| Array.new(5) {|j| i*j } }
=> [[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8], [0, 3, 6, 9, 12], [0, 4, 8, 12, 16]]
irb(main):339:0> pp ary
NoMethodError: undefined method `<<' for #<FXIrb:0x6229524>
from ..../Ruby/lib/ruby/1.8/prettyprint.rb:146:in `text'
from ..../Ruby/lib/ruby/1.8/prettyprint.rb:198:in `group'
from ..../Ruby/lib/ruby/1.8/pp.rb:140:in `pp'
from ..../Ruby/lib/ruby/1.8/PP.rb:77:in `pp'
from ..../Ruby/lib/ruby/1.8/pp.rb:119:in `guard_inspect_key'
from ..../Ruby/lib/ruby/1.8/PP.rb:77:in `pp'
from ..../Ruby/lib/ruby/1.8/PP.rb:60:in `pp'
from ..../Ruby/lib/ruby/1.8/PP.rb:59:in `each'
from ..../Ruby/lib/ruby/1.8/PP.rb:59:in `pp'
from (irb):339
from :0

2 个答案:

答案 0 :(得分:6)

尝试明确要求pp

require "pp"

如果这不起作用,请尝试升级到ruby 1.8.7或使用其他“漂亮的打印机”,例如awesome print

答案 1 :(得分:0)

试试这个:

def <<(text)
  print text
end

irb(main):011:0> pp [1,2]
[1, 2]
=> nil

ruby​​ 1.8.6(2007-03-13 patchlevel 0)[i386-mswin32]