From d993e38f1898a2edf29f304c8aa3b34aceb34c35 Mon Sep 17 00:00:00 2001 From: dave Date: Mon, 29 Dec 2003 03:56:22 +0000 Subject: Add RDoc for Kernel global functions, tidy array and error git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- variable.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'variable.c') 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 + * Kernel::untrace_var. + * + * trace_var :$_, proc {|v| puts "$_ is now '#{v}'" } + * $_ = "hello" + * $_ = ' there' + * + * produces: + * + * $_ 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() { -- cgit v1.2.3