summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/variable.c b/variable.c
index 2a7b7956d6..17832df8e6 100644
--- a/variable.c
+++ b/variable.c
@@ -531,6 +531,29 @@ rb_trace_eval(cmd, val)
rb_eval_cmd(cmd, rb_ary_new3(1, val), 0);
}
+/*
+ * call-seq:
+ * trace_var(symbol, cmd ) => nil
+ * trace_var(symbol) {|val| block } => nil
+ *
+ * Controls tracing of assignments to global variables. The parameter
+ * +symbol_ identifies the variable (as either a string name or a
+ * symbol identifier). _cmd_ (which may be a string or a
+ * +Proc+ object) or block is executed whenever the variable
+ * is assigned. The block or +Proc+ object receives the
+ * variable's new value as a parameter. Also see
+ * <code>Kernel::untrace_var</code>.
+ *
+ * trace_var :$_, proc {|v| puts "$_ is now '#{v}'" }
+ * $_ = "hello"
+ * $_ = ' there'
+ *
+ * <em>produces:</em>
+ *
+ * $_ is now 'hello'
+ * $_ is now ' there'
+ */
+
VALUE
rb_f_trace_var(argc, argv)
int argc;
@@ -584,6 +607,16 @@ remove_trace(var)
var->trace = t.next;
}
+/*
+ * call-seq:
+ * untrace_var(symbol [, cmd] ) => array or nil
+ *
+ * Removes tracing for the specified command on the given global
+ * variable and returns +nil+. If no command is specified,
+ * removes all tracing for that variable and returns an array
+ * containing the commands actually removed.
+ */
+
VALUE
rb_f_untrace_var(argc, argv)
int argc;
@@ -722,6 +755,15 @@ gvar_i(key, entry, ary)
return ST_CONTINUE;
}
+/*
+ * call-seq:
+ * global_variables => array
+ *
+ * Returns an array of the names of global variables.
+ *
+ * global_variables.grep /std/ #=> ["$stderr", "$stdout", "$stdin"]
+ */
+
VALUE
rb_f_global_variables()
{