Bug #2147
closedCannot pp DelegateClass derived classes: undefined method `inspect' NameError
Description
=begin
pp derived_from_delegate_class fails with a NameError under 1.9.1, apparently unable to find the method #inspect(), though a direct call to that method works fine:
=== begin ===
require 'delegate'
require 'pp'
class A < DelegateClass(Array); end
puts "ruby-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} (#{RUBY_PLATFORM})"
puts A.new([]).inspect
pp A.new([])
=== end ===
Compare:
$ ruby-1.8.7 delegate-inspect.rb
ruby-1.8.7-p160 (i686-linux)
[]
[]
$ ruby-1.9 delegate-inspect.rb
ruby-1.9.1-p243 (i686-linux)
[]
/opt/ruby-1.9.1/lib/ruby/1.9.1/pp.rb:286:in method': undefined method
inspect' for class A' (NameError) from /opt/ruby-1.9.1/lib/ruby/1.9.1/pp.rb:286:in
call'
from /opt/ruby-1.9.1/lib/ruby/1.9.1/pp.rb:286:in pretty_print' from /opt/ruby-1.9.1/lib/ruby/1.9.1/pp.rb:154:in
block in pp'
from /opt/ruby-1.9.1/lib/ruby/1.9.1/prettyprint.rb:200:in block (2 levels) in group' from /opt/ruby-1.9.1/lib/ruby/1.9.1/prettyprint.rb:227:in
nest'
from /opt/ruby-1.9.1/lib/ruby/1.9.1/prettyprint.rb:200:in block in group' from /opt/ruby-1.9.1/lib/ruby/1.9.1/prettyprint.rb:212:in
group_sub'
from /opt/ruby-1.9.1/lib/ruby/1.9.1/prettyprint.rb:199:in group' from /opt/ruby-1.9.1/lib/ruby/1.9.1/pp.rb:154:in
pp'
from /opt/ruby-1.9.1/lib/ruby/1.9.1/pp.rb:77:in block in pp' from /opt/ruby-1.9.1/lib/ruby/1.9.1/pp.rb:121:in
guard_inspect_key'
from /opt/ruby-1.9.1/lib/ruby/1.9.1/pp.rb:77:in pp' from /opt/ruby-1.9.1/lib/ruby/1.9.1/pp.rb:59:in
block in pp'
from /opt/ruby-1.9.1/lib/ruby/1.9.1/pp.rb:59:in each' from /opt/ruby-1.9.1/lib/ruby/1.9.1/pp.rb:59:in
pp'
from delegate-inspect.rb:8:in `'
=end
Files
Updated by pilcrow (Mike Pomraning) about 15 years ago
=begin
This is also a problem unit testing anything derived from DelegateClass: AssertionMessage.delayed_diff calls a method, convert(), which may call pp, meaning that something as simple as:
assert_equal [1,2,3], array_like_derived_from_delegateclass
will fail with an internal NameError (!).
=end
Updated by yugui (Yuki Sonoda) about 15 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
=begin
This issue was solved with changeset r25951.
Mike, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
=end