зеркало из https://github.com/github/ruby.git
* intern.h, object.c, variable.c (rb_mod_constants): added an optional
flag to search ancestors, which is defaulted to true, as well as const_defined? and const_get. [ruby-dev:29989] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11338 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
8d69c7f116
Коммит
f4aca06c84
|
@ -1,3 +1,9 @@
|
|||
Tue Dec 5 00:19:14 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* intern.h, object.c, variable.c (rb_mod_constants): added an optional
|
||||
flag to search ancestors, which is defaulted to true, as well as
|
||||
const_defined? and const_get. [ruby-dev:29989]
|
||||
|
||||
Mon Dec 4 23:49:28 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* instruby.rb (install_recursive): get rid of warning.
|
||||
|
|
8
eval.c
8
eval.c
|
@ -1906,11 +1906,15 @@ rb_mod_nesting(void)
|
|||
*/
|
||||
|
||||
static VALUE
|
||||
rb_mod_s_constants(void)
|
||||
rb_mod_s_constants(int argc, VALUE *argv, VALUE mod)
|
||||
{
|
||||
NODE *cbase = ruby_cref;
|
||||
void *data = 0;
|
||||
|
||||
if (argc > 0) {
|
||||
return rb_mod_constants(argc, argv, rb_cModule);
|
||||
}
|
||||
|
||||
while (cbase) {
|
||||
if (!NIL_P(cbase->nd_clss)) {
|
||||
data = rb_mod_const_at(cbase->nd_clss, data);
|
||||
|
@ -7952,7 +7956,7 @@ Init_eval(void)
|
|||
rb_define_private_method(rb_cModule, "define_method", rb_mod_define_method, -1);
|
||||
|
||||
rb_define_singleton_method(rb_cModule, "nesting", rb_mod_nesting, 0);
|
||||
rb_define_singleton_method(rb_cModule, "constants", rb_mod_s_constants, 0);
|
||||
rb_define_singleton_method(rb_cModule, "constants", rb_mod_s_constants, -1);
|
||||
|
||||
rb_define_singleton_method(ruby_top_self, "include", top_include, -1);
|
||||
rb_define_singleton_method(ruby_top_self, "public", top_public, -1);
|
||||
|
|
3
intern.h
3
intern.h
|
@ -562,7 +562,7 @@ VALUE rb_obj_remove_instance_variable(VALUE, VALUE);
|
|||
void *rb_mod_const_at(VALUE, void*);
|
||||
void *rb_mod_const_of(VALUE, void*);
|
||||
VALUE rb_const_list(void*);
|
||||
VALUE rb_mod_constants(VALUE);
|
||||
VALUE rb_mod_constants(int, VALUE *, VALUE);
|
||||
VALUE rb_mod_remove_const(VALUE, VALUE);
|
||||
int rb_const_defined(VALUE, ID);
|
||||
int rb_const_defined_at(VALUE, ID);
|
||||
|
@ -573,7 +573,6 @@ VALUE rb_const_get_at(VALUE, ID);
|
|||
VALUE rb_const_get_from(VALUE, ID);
|
||||
VALUE rb_const_get_fallback(VALUE, ID, struct RNode *);
|
||||
void rb_const_set(VALUE, ID, VALUE);
|
||||
VALUE rb_mod_constants(VALUE);
|
||||
VALUE rb_mod_const_missing(VALUE,VALUE);
|
||||
VALUE rb_cvar_defined(VALUE, ID);
|
||||
#define RB_CVAR_SET_4ARGS 1
|
||||
|
|
2
object.c
2
object.c
|
@ -2406,7 +2406,7 @@ Init_Object(void)
|
|||
rb_define_method(rb_cModule, "local_methods",
|
||||
rb_class_local_methods, 0); /* in class.c */
|
||||
|
||||
rb_define_method(rb_cModule, "constants", rb_mod_constants, 0); /* in variable.c */
|
||||
rb_define_method(rb_cModule, "constants", rb_mod_constants, -1); /* in variable.c */
|
||||
rb_define_method(rb_cModule, "const_get", rb_mod_const_get, -1);
|
||||
rb_define_method(rb_cModule, "const_set", rb_mod_const_set, 2);
|
||||
rb_define_method(rb_cModule, "const_defined?", rb_mod_const_defined, -1);
|
||||
|
|
31
variable.c
31
variable.c
|
@ -1438,17 +1438,38 @@ rb_const_list(void *data)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* mod.constants => array
|
||||
*
|
||||
* mod.constants(inherit=true) => array
|
||||
*
|
||||
* Returns an array of the names of the constants accessible in
|
||||
* <i>mod</i>. This includes the names of constants in any included
|
||||
* modules (example at start of section).
|
||||
* modules (example at start of section), unless the <i>all</i>
|
||||
* parameter is set to <code>false</code>.
|
||||
*
|
||||
* IO.constants.include?("SYNC") => true
|
||||
* IO.constants(false).include?("SYNC") => false
|
||||
*
|
||||
* Also see <code>Module::const_defined?</code>.
|
||||
*/
|
||||
|
||||
VALUE
|
||||
rb_mod_constants(VALUE mod)
|
||||
rb_mod_constants(int argc, VALUE *argv, VALUE mod)
|
||||
{
|
||||
return rb_const_list(rb_mod_const_of(mod, 0));
|
||||
VALUE inherit;
|
||||
st_table *tbl;
|
||||
|
||||
if (argc == 0) {
|
||||
inherit = Qtrue;
|
||||
}
|
||||
else {
|
||||
rb_scan_args(argc, argv, "01", &inherit);
|
||||
}
|
||||
if (RTEST(inherit)) {
|
||||
tbl = rb_mod_const_of(mod, 0);
|
||||
}
|
||||
else {
|
||||
tbl = rb_mod_const_at(mod, 0);
|
||||
}
|
||||
return rb_const_list(tbl);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
Загрузка…
Ссылка в новой задаче