Module: GVars
- Defined in:
- lib/gvars.rb,
lib/gvars/version.rb,
ext/gvars/gvars.c
Constant Summary collapse
- VERSION =
'1.0.1'
Class Method Summary collapse
- .[](name) ⇒ Object
- .[]=(name, value) ⇒ Object
- .alias_global_variable(new, old) ⇒ Object
- .debug? ⇒ Boolean
- .define_hooked_method(*args) ⇒ Object
-
.define_virtual_method(*args) ⇒ Object
TODO: ID2SYM(id).
- .each ⇒ Object
-
.global_variable_get(name) ⇒ Object
Define module-level functions that can be used as mixins.
- .global_variable_set(name, value) ⇒ Object
-
.global_variables ⇒ Object
Don’t make it an instance method, as it exists in Kernel.
- .to_h ⇒ Object
Class Method Details
.[](name) ⇒ Object
52 53 54 55 56 |
# File 'ext/gvars/gvars.c', line 52
static VALUE
gvars_f_global_variable_aref(VALUE self, VALUE name)
{
return rb_gv_get(get_global_name(&name, true));
}
|
.[]=(name, value) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'ext/gvars/gvars.c', line 64
static VALUE
gvars_f_global_variable_aset(VALUE self, VALUE name, VALUE value)
{
char *sname = get_global_name(&name, true);
if (gvars_debug_enabled()) {
char *sname_without_dollar = sname;
if (sname_without_dollar[0] == '$') {
++sname_without_dollar;
}
VALUE msg = rb_sprintf("GVars: setting global $%s to: %"PRIsVALUE"\n",
sname_without_dollar, rb_inspect(value));
rb_io_write(rb_gv_get("$stderr"), msg);
}
return rb_gv_set(sname, value);
}
|
.alias_global_variable(new, old) ⇒ Object
89 90 91 92 93 94 95 |
# File 'ext/gvars/gvars.c', line 89
static VALUE
gvars_f_alias_global_variable(VALUE self, VALUE new, VALUE old)
{
ID newid = rb_intern(get_global_name(&new, true));
rb_alias_variable(newid, rb_intern(get_global_name(&old, true)));
return ID2SYM(newid);
}
|
.debug? ⇒ Boolean
14 15 16 17 18 |
# File 'ext/gvars/gvars.c', line 14
static VALUE
gvars_f_defined_p(VALUE self)
{
return gvars_debug_enabled() ? Qtrue : Qfalse;
}
|
.define_hooked_method(*args) ⇒ Object
376 377 378 379 380 |
# File 'ext/gvars/gvars.c', line 376
static VALUE
gvars_f_define_hooked_method(int argc, VALUE *argv, VALUE self)
{
return gvars_f_define_virtual_method_foo(argc, argv, self, true);
}
|
.define_virtual_method(*args) ⇒ Object
TODO: ID2SYM(id)
370 371 372 373 374 |
# File 'ext/gvars/gvars.c', line 370
static VALUE
gvars_f_define_virtual_method(int argc, VALUE *argv, VALUE self)
{
return gvars_f_define_virtual_method_foo(argc, argv, self, false);
}
|
.each ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'ext/gvars/gvars.c', line 103
static VALUE
gvars_f_each(VALUE self)
{
RETURN_SIZED_ENUMERATOR(self, 0, 0, gvars_enum_length);
VALUE gvars = gvars_f_global_variables(self);
for (long i = 0; i < RARRAY_LEN(gvars); i++) {
VALUE key = RARRAY_AREF(gvars, i);
rb_yield(rb_ary_new_from_args(2, key, gvars_f_global_variable_get(self, key)));
}
return self;
}
|
.global_variable_get(name) ⇒ Object
Define module-level functions that can be used as mixins
46 47 48 49 50 |
# File 'ext/gvars/gvars.c', line 46
static VALUE
gvars_f_global_variable_get(VALUE self, VALUE name)
{
return rb_gv_get(get_global_name(&name, false));
}
|
.global_variable_set(name, value) ⇒ Object
58 59 60 61 62 |
# File 'ext/gvars/gvars.c', line 58
static VALUE
gvars_f_global_variable_set(VALUE self, VALUE name, VALUE value)
{
return rb_gv_set(get_global_name(&name, false), value);
}
|
.global_variables ⇒ Object
Don’t make it an instance method, as it exists in Kernel
83 84 85 86 87 |
# File 'ext/gvars/gvars.c', line 83
static VALUE
gvars_f_global_variables(VALUE self)
{
return rb_f_global_variables();
}
|
.to_h ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'ext/gvars/gvars.c', line 117
static VALUE
gvars_f_to_h(VALUE self)
{
VALUE gvars = gvars_f_global_variables(self);
VALUE hash = rb_hash_new_capa(RARRAY_LEN(gvars));
for (long i = 0; i < RARRAY_LEN(gvars); i++) {
VALUE key = RARRAY_AREF(gvars, i);
rb_hash_aset(hash, key, gvars_f_global_variable_get(self, key));
}
return hash;
}
|