aboutsummaryrefslogtreecommitdiffstats
path: root/proc.c
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-26 08:38:35 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-26 08:38:35 +0000
commit8aa79a292cbfab685ec193b36874746ea988fac6 (patch)
tree7ef5c6a23b743dcf889875869fdffab9c5d9cda3 /proc.c
parentf0a5ee4b90119f518daf66ef7237d7179fb1ee2f (diff)
downloadruby-8aa79a292cbfab685ec193b36874746ea988fac6.tar.gz
proc.c (bind_location): Add Binding#source_location
Fixes #14230 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'proc.c')
-rw-r--r--proc.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/proc.c b/proc.c
index 9dbc78ae4a..23c4d3a2d4 100644
--- a/proc.c
+++ b/proc.c
@@ -12,6 +12,7 @@
#include "eval_intern.h"
#include "internal.h"
#include "gc.h"
+#include "vm_core.h"
#include "iseq.h"
/* Proc.new with no block will raise an exception in the future
@@ -611,6 +612,24 @@ bind_receiver(VALUE bindval)
return vm_block_self(&bind->block);
}
+/*
+ * call-seq:
+ * binding.source_location -> [String, Integer]
+ *
+ * Returns the Ruby source filename and line number of the binding object.
+ */
+static VALUE
+bind_location(VALUE bindval)
+{
+ VALUE loc[2];
+ const rb_binding_t *bind;
+ GetBindingPtr(bindval, bind);
+ loc[0] = pathobj_path(bind->pathobj);
+ loc[1] = INT2FIX(bind->first_lineno);
+
+ return rb_ary_new4(2, loc);
+}
+
static VALUE
cfunc_proc_new(VALUE klass, VALUE ifunc, int8_t is_lambda)
{
@@ -3223,5 +3242,6 @@ Init_Binding(void)
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_method(rb_cBinding, "source_location", bind_location, 0);
rb_define_global_function("binding", rb_f_binding, 0);
}