lib/pp.rb: Use UnboundMethod#bind_call instead of .bind(obj).call(...)
Related to [Feature #15955].
This commit is contained in:
parent
09c940b17f
commit
c9fc82983c
2
NEWS
2
NEWS
@ -177,7 +177,7 @@ without allocation of intermediate Method object.
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
class Bar < Foo
|
class Bar < Foo
|
||||||
def add_1 # override
|
def add_1(x) # override
|
||||||
x + 2
|
x + 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
10
lib/pp.rb
10
lib/pp.rb
@ -89,7 +89,7 @@ class PP < PrettyPrint
|
|||||||
|
|
||||||
# :stopdoc:
|
# :stopdoc:
|
||||||
def PP.mcall(obj, mod, meth, *args, &block)
|
def PP.mcall(obj, mod, meth, *args, &block)
|
||||||
mod.instance_method(meth).bind(obj).call(*args, &block)
|
mod.instance_method(meth).bind_call(obj, *args, &block)
|
||||||
end
|
end
|
||||||
# :startdoc:
|
# :startdoc:
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ class PP < PrettyPrint
|
|||||||
# A convenience method, like object_group, but also reformats the Object's
|
# A convenience method, like object_group, but also reformats the Object's
|
||||||
# object_id.
|
# object_id.
|
||||||
def object_address_group(obj, &block)
|
def object_address_group(obj, &block)
|
||||||
str = Kernel.instance_method(:to_s).bind(obj).call
|
str = Kernel.instance_method(:to_s).bind_call(obj)
|
||||||
str.chomp!('>')
|
str.chomp!('>')
|
||||||
group(1, str, '>', &block)
|
group(1, str, '>', &block)
|
||||||
end
|
end
|
||||||
@ -279,9 +279,9 @@ class PP < PrettyPrint
|
|||||||
# This module provides predefined #pretty_print methods for some of
|
# This module provides predefined #pretty_print methods for some of
|
||||||
# the most commonly used built-in classes for convenience.
|
# the most commonly used built-in classes for convenience.
|
||||||
def pretty_print(q)
|
def pretty_print(q)
|
||||||
method_method = Object.instance_method(:method).bind(self)
|
umethod_method = Object.instance_method(:method)
|
||||||
begin
|
begin
|
||||||
inspect_method = method_method.call(:inspect)
|
inspect_method = umethod_method.bind_call(self, :inspect)
|
||||||
rescue NameError
|
rescue NameError
|
||||||
end
|
end
|
||||||
if inspect_method && inspect_method.owner != Kernel
|
if inspect_method && inspect_method.owner != Kernel
|
||||||
@ -318,7 +318,7 @@ class PP < PrettyPrint
|
|||||||
# However, doing this requires that every class that #inspect is called on
|
# However, doing this requires that every class that #inspect is called on
|
||||||
# implement #pretty_print, or a RuntimeError will be raised.
|
# implement #pretty_print, or a RuntimeError will be raised.
|
||||||
def pretty_print_inspect
|
def pretty_print_inspect
|
||||||
if Object.instance_method(:method).bind(self).call(:pretty_print).owner == PP::ObjectMixin
|
if Object.instance_method(:method).bind_call(self, :pretty_print).owner == PP::ObjectMixin
|
||||||
raise "pretty_print is not overridden for #{self.class}"
|
raise "pretty_print is not overridden for #{self.class}"
|
||||||
end
|
end
|
||||||
PP.singleline_pp(self, ''.dup)
|
PP.singleline_pp(self, ''.dup)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user