mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
forwardable.rb: private methods
* lib/forwardable.rb (_delegator_method): allow private methods to be delegated, with warnings. [ruby-core:77341] [Bug #12782] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56210 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1e1a114c25
commit
ef13e60fe0
2 changed files with 29 additions and 13 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Fri Sep 23 15:47:04 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/forwardable.rb (_delegator_method): allow private methods to
|
||||||
|
be delegated, with warnings. [ruby-core:77341] [Bug #12782]
|
||||||
|
|
||||||
Fri Sep 23 12:15:29 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Fri Sep 23 12:15:29 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* compile.c (iseq_peephole_optimize): enable tail call
|
* compile.c (iseq_peephole_optimize): enable tail call
|
||||||
|
|
|
@ -195,31 +195,42 @@ module Forwardable
|
||||||
accessor = "#{accessor}()"
|
accessor = "#{accessor}()"
|
||||||
end
|
end
|
||||||
|
|
||||||
unless begin
|
vm = RubyVM::InstructionSequence
|
||||||
iseq = RubyVM::InstructionSequence
|
method_call = ".__send__(:#{method}, *args, &block)"
|
||||||
.compile("().#{method}", nil, nil, 0, false)
|
if begin
|
||||||
|
iseq = vm.compile("().#{method}", nil, nil, 0, false)
|
||||||
rescue SyntaxError
|
rescue SyntaxError
|
||||||
else
|
else
|
||||||
iseq.to_a.dig(-1, 1, 1, :mid) == method.to_sym
|
iseq.to_a.dig(-1, 1, 1, :mid) == method.to_sym
|
||||||
end
|
end
|
||||||
method_call = "__send__(:#{method}, *args, &block)"
|
loc, = caller_locations(2,1)
|
||||||
|
pre = "_ ="
|
||||||
|
mesg = "#{Module === obj ? obj : obj.class}\##{ali} at #{loc.path}:#{loc.lineno} forwarding to private method "
|
||||||
|
method_call = "#{<<-"begin;"}\n#{<<-"end;".chomp}"
|
||||||
|
begin;
|
||||||
|
unless ::Kernel.instance_method(:respond_to?).bind(_).call(:"#{method}")
|
||||||
|
::Kernel.warn "\#{caller_locations(1)[0]}: "#{mesg.dump}"\#{_.class}"'##{method}'
|
||||||
|
_#{method_call}
|
||||||
else
|
else
|
||||||
method_call = "#{method}(*args, &block)"
|
_.#{method}(*args, &block)
|
||||||
|
end
|
||||||
|
end;
|
||||||
end
|
end
|
||||||
|
|
||||||
line_no = __LINE__+1; str = "#{<<-"begin;"}\n#{<<-"end;"}"
|
line_no = __LINE__+1; str = "#{<<-"begin;"}\n#{<<-"end;"}"
|
||||||
begin;
|
begin;
|
||||||
proc do
|
proc do
|
||||||
def #{ali}(*args, &block)
|
def #{ali}(*args, &block)
|
||||||
|
#{pre}
|
||||||
begin
|
begin
|
||||||
#{accessor}
|
#{accessor}
|
||||||
end.#{method_call}
|
end#{method_call}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
RubyVM::InstructionSequence
|
puts str
|
||||||
.compile(str, __FILE__, __FILE__, line_no,
|
vm.compile(str, __FILE__, __FILE__, line_no,
|
||||||
trace_instruction: false,
|
trace_instruction: false,
|
||||||
tailcall_optimization: true)
|
tailcall_optimization: true)
|
||||||
.eval
|
.eval
|
||||||
|
|
Loading…
Add table
Reference in a new issue