[前][次][番号順一覧][スレッド一覧]

ruby-changes:46131

From: akr <ko1@a...>
Date: Tue, 4 Apr 2017 21:54:48 +0900 (JST)
Subject: [ruby-changes:46131] akr:r58245 (trunk): Refactored using Method#owner.

akr	2017-04-04 21:54:42 +0900 (Tue, 04 Apr 2017)

  New Revision: 58245

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58245

  Log:
    Refactored using Method#owner.

  Modified files:
    trunk/lib/pp.rb
Index: lib/pp.rb
===================================================================
--- lib/pp.rb	(revision 58244)
+++ lib/pp.rb	(revision 58245)
@@ -311,7 +311,7 @@ class PP < PrettyPrint https://github.com/ruby/ruby/blob/trunk/lib/pp.rb#L311
         inspect_method = method_method.call(:inspect)
       rescue NameError
       end
-      if inspect_method && /\(Kernel\)#/ !~ inspect_method.inspect
+      if inspect_method && inspect_method.owner != Kernel
         q.text self.inspect
       elsif !inspect_method && self.respond_to?(:inspect)
         q.text self.inspect
@@ -345,7 +345,7 @@ class PP < PrettyPrint https://github.com/ruby/ruby/blob/trunk/lib/pp.rb#L345
     # However, doing this requires that every class that #inspect is called on
     # implement #pretty_print, or a RuntimeError will be raised.
     def pretty_print_inspect
-      if /\(PP::ObjectMixin\)#/ =~ Object.instance_method(:method).bind(self).call(:pretty_print).inspect
+      if Object.instance_method(:method).bind(self).call(:pretty_print).owner == PP::ObjectMixin
         raise "pretty_print is not overridden for #{self.class}"
       end
       PP.singleline_pp(self, ''.dup)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]