From 43ba2c01e746992e9658000e4df7bb025bfb6b01 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 1 Jul 2014 17:24:02 +0000 Subject: 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 --- proc.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'proc.c') diff --git a/proc.c b/proc.c index 1c37acb3d3..f81483c7b1 100644 --- a/proc.c +++ b/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; } +/* + * 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 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_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, "receiver", bind_receiver, 0); rb_define_global_function("binding", rb_f_binding, 0); } -- cgit v1.2.3