summaryrefslogtreecommitdiffstats
path: root/variable.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-12-04 15:19:33 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-12-04 15:19:33 +0000
commitacb949ff5ab95773175661de319fd1ab8af78330 (patch)
tree9041f38521e1caf750aae67f0930686778c89c97 /variable.c
parentd8a9c4e13ab1715609457fa960d7dd9a7c1439ce (diff)
downloadruby-acb949ff5ab95773175661de319fd1ab8af78330.tar.gz
ruby-acb949ff5ab95773175661de319fd1ab8af78330.tar.xz
ruby-acb949ff5ab95773175661de319fd1ab8af78330.zip
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@11338 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/variable.c b/variable.c
index 9c51b9d4d..c992bcc9c 100644
--- a/variable.c
+++ b/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