mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* eval.c (rb_f_public_send): rename invoke_method to public_send.
it now invokes public method only no matter how it's called. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14173 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7ded13f54b
commit
5ee029f62c
4 changed files with 17 additions and 20 deletions
|
@ -1,3 +1,8 @@
|
|||
Mon Dec 10 14:33:50 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* eval.c (rb_f_public_send): rename invoke_method to public_send.
|
||||
it now invokes public method only no matter how it's called.
|
||||
|
||||
Mon Dec 10 14:00:43 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* transcode.c: new file to provide encoding conversion features.
|
||||
|
|
|
@ -336,7 +336,7 @@ assert_equal '1', %q( class C; def m(x,a=7) a end end;
|
|||
assert_equal '[1, 2]', %q( class C; def m(*a) a end end;
|
||||
C.new.send(:m,1,2).inspect )
|
||||
assert_equal '1', %q( class C; def m() 7 end; private :m end
|
||||
begin C.new.invoke_method(:m); rescue NoMethodError; 1 end )
|
||||
begin C.new.public_send(:m); rescue NoMethodError; 1 end )
|
||||
assert_equal '1', %q( class C; def m() 1 end; private :m end
|
||||
C.new.send(:m) )
|
||||
|
||||
|
@ -919,8 +919,8 @@ assert_equal %q{[:ok, :ok, :ok, :ok, :ok, :ok, :ng, :ng]}, %q{
|
|||
test{o2.mm}
|
||||
test{o1.send :m}
|
||||
test{o2.send :mm}
|
||||
test{o1.invoke_method :m}
|
||||
test{o2.invoke_method :mm}
|
||||
test{o1.public_send :m}
|
||||
test{o2.public_send :mm}
|
||||
test{o1.method(:m).call}
|
||||
test{o2.method(:mm).call}
|
||||
$ans
|
||||
|
|
22
eval.c
22
eval.c
|
@ -1509,27 +1509,19 @@ rb_f_send(int argc, VALUE *argv, VALUE recv)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* obj.invoke_method(symbol [, args...]) => obj
|
||||
* obj.public_send(symbol [, args...]) => obj
|
||||
*
|
||||
* Invokes the method identified by _symbol_, passing it any
|
||||
* arguments specified. Unlike send, invoke_method calls public
|
||||
* methods only, unless it's invoked in a function call style.
|
||||
* arguments specified. Unlike send, public_send calls public
|
||||
* methods only.
|
||||
*
|
||||
* 1.invoke_method(:puts, "hello") # causes NoMethodError
|
||||
* 1.public_send(:puts, "hello") # causes NoMethodError
|
||||
*/
|
||||
|
||||
VALUE
|
||||
rb_invoke_method(int argc, VALUE *argv, VALUE recv)
|
||||
rb_f_public_send(int argc, VALUE *argv, VALUE recv)
|
||||
{
|
||||
int rb_vm_cfunc_funcall_p(rb_control_frame_t *);
|
||||
int scope = NOEX_PUBLIC;
|
||||
rb_thread_t *th = GET_THREAD();
|
||||
|
||||
if (rb_vm_cfunc_funcall_p(th->cfp)) {
|
||||
scope = NOEX_NOSUPER | NOEX_PRIVATE;
|
||||
}
|
||||
|
||||
return send_internal(argc, argv, recv, scope);
|
||||
return send_internal(argc, argv, recv, NOEX_PUBLIC);
|
||||
}
|
||||
|
||||
VALUE
|
||||
|
@ -2760,7 +2752,7 @@ Init_eval(void)
|
|||
|
||||
rb_define_method(rb_cBasicObject, "__send__", rb_f_send, -1);
|
||||
rb_define_method(rb_mKernel, "send", rb_f_send, -1);
|
||||
rb_define_method(rb_mKernel, "invoke_method", rb_invoke_method, -1);
|
||||
rb_define_method(rb_mKernel, "public_send", rb_f_public_send, -1);
|
||||
|
||||
rb_define_method(rb_mKernel, "instance_eval", rb_obj_instance_eval, -1);
|
||||
rb_define_method(rb_mKernel, "instance_exec", rb_obj_instance_exec, -1);
|
||||
|
|
|
@ -115,7 +115,7 @@
|
|||
# implementation, see SimpleDelegator.
|
||||
#
|
||||
class Delegator
|
||||
preserved = [:__id__, :object_id, :__send__, :invoke_method, :respond_to?, :send]
|
||||
preserved = [:__id__, :object_id, :__send__, :public_send, :respond_to?, :send]
|
||||
instance_methods.each do |m|
|
||||
next if preserved.include?(m)
|
||||
undef_method m
|
||||
|
@ -262,7 +262,7 @@ def DelegateClass(superclass)
|
|||
klass = Class.new
|
||||
methods = superclass.public_instance_methods(true)
|
||||
methods -= [
|
||||
:__id__, :object_id, :__send__, :invoke_method, :respond_to?, :send,
|
||||
:__id__, :object_id, :__send__, :public_send, :respond_to?, :send,
|
||||
:==, :equal?, :initialize, :method_missing, :__getobj__, :__setobj__,
|
||||
:clone, :dup, :marshal_dump, :marshal_load,
|
||||
]
|
||||
|
|
Loading…
Add table
Reference in a new issue