mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
proc.c: Binding#receiver
* proc.c (bind_receiver): new method to return the bound receiver of the binding object. [ruby-dev:47613] [Feature #8779] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
02c391a1c9
commit
43ba2c01e7
4 changed files with 34 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Wed Jul 2 02:23:52 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* proc.c (bind_receiver): new method to return the bound receiver
|
||||||
|
of the binding object. [ruby-dev:47613] [Feature #8779]
|
||||||
|
|
||||||
Wed Jul 2 02:14:37 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Jul 2 02:14:37 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* proc.c (bind_local_variables): update env from envval for each
|
* proc.c (bind_local_variables): update env from envval for each
|
||||||
|
|
1
NEWS
1
NEWS
|
@ -18,6 +18,7 @@ with all sufficient information, see the ChangeLog file.
|
||||||
* Binding
|
* Binding
|
||||||
* New methods:
|
* New methods:
|
||||||
* Binding#local_variables
|
* Binding#local_variables
|
||||||
|
* Binding#receiver
|
||||||
|
|
||||||
* Enumerable
|
* Enumerable
|
||||||
* New methods:
|
* New methods:
|
||||||
|
|
18
proc.c
18
proc.c
|
@ -609,6 +609,23 @@ bind_local_variable_defined_p(VALUE bindval, VALUE sym)
|
||||||
return get_local_variable_ptr(bind->env, lid) ? Qtrue : Qfalse;
|
return get_local_variable_ptr(bind->env, lid) ? Qtrue : Qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* call-seq:
|
||||||
|
* binding.receiver -> object
|
||||||
|
*
|
||||||
|
* Returns the bound receiver of the binding object.
|
||||||
|
*/
|
||||||
|
static VALUE
|
||||||
|
bind_receiver(VALUE bindval)
|
||||||
|
{
|
||||||
|
const rb_binding_t *bind;
|
||||||
|
const rb_env_t *env;
|
||||||
|
|
||||||
|
GetBindingPtr(bindval, bind);
|
||||||
|
GetEnvPtr(bind->env, env);
|
||||||
|
return env->block.self;
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
proc_new(VALUE klass, int is_lambda)
|
proc_new(VALUE klass, int is_lambda)
|
||||||
{
|
{
|
||||||
|
@ -2859,6 +2876,7 @@ Init_Binding(void)
|
||||||
rb_define_method(rb_cBinding, "local_variable_get", bind_local_variable_get, 1);
|
rb_define_method(rb_cBinding, "local_variable_get", bind_local_variable_get, 1);
|
||||||
rb_define_method(rb_cBinding, "local_variable_set", bind_local_variable_set, 2);
|
rb_define_method(rb_cBinding, "local_variable_set", bind_local_variable_set, 2);
|
||||||
rb_define_method(rb_cBinding, "local_variable_defined?", bind_local_variable_defined_p, 1);
|
rb_define_method(rb_cBinding, "local_variable_defined?", bind_local_variable_defined_p, 1);
|
||||||
|
rb_define_method(rb_cBinding, "receiver", bind_receiver, 0);
|
||||||
rb_define_global_function("binding", rb_f_binding, 0);
|
rb_define_global_function("binding", rb_f_binding, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1299,4 +1299,14 @@ class TestProc < Test::Unit::TestCase
|
||||||
assert_equal(true, b.local_variable_defined?(:a))
|
assert_equal(true, b.local_variable_defined?(:a))
|
||||||
assert_equal(false, b.local_variable_defined?(:b))
|
assert_equal(false, b.local_variable_defined?(:b))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_binding_receiver
|
||||||
|
feature8779 = '[ruby-dev:47613] [Feature #8779]'
|
||||||
|
|
||||||
|
assert_same(self, binding.receiver, feature8779)
|
||||||
|
|
||||||
|
obj = Object.new
|
||||||
|
def obj.b; binding; end
|
||||||
|
assert_same(obj, obj.b.receiver, feature8779)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue