* object.c (rb_mod_const_get, rb_mod_const_defined): added optional
flag to search ancestors, which is defaulted to true. fixed: [ruby-talk:175899] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9841 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
dc2732c84f
commit
dd677b700c
12
ChangeLog
12
ChangeLog
@ -1,3 +1,9 @@
|
|||||||
|
Tue Jan 17 23:05:21 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* object.c (rb_mod_const_get, rb_mod_const_defined): added optional
|
||||||
|
flag to search ancestors, which is defaulted to true.
|
||||||
|
fixed: [ruby-talk:175899]
|
||||||
|
|
||||||
Tue Jan 17 11:31:47 2006 NAKAMURA Usaku <usa@ruby-lang.org>
|
Tue Jan 17 11:31:47 2006 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* win32/setup.mak (MAKE): workaround for nmake 8.
|
* win32/setup.mak (MAKE): workaround for nmake 8.
|
||||||
@ -35,13 +41,13 @@ Fri Jan 13 19:26:15 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
|||||||
Thu Jan 12 11:53:08 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
Thu Jan 12 11:53:08 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
||||||
|
|
||||||
* ext/tk/sample/tkballoonhelp.rb: [bug fix] couldn't add to a widget
|
* ext/tk/sample/tkballoonhelp.rb: [bug fix] couldn't add to a widget
|
||||||
which is constructed with TkComposite module.
|
which is constructed with TkComposite module.
|
||||||
[new feature] support 'command' option which is called just before
|
[new feature] support 'command' option which is called just before
|
||||||
popping up the balloon help.
|
popping up the balloon help.
|
||||||
|
|
||||||
Wed Jan 11 00:12:29 2006 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
|
Wed Jan 11 00:12:29 2006 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
|
||||||
|
|
||||||
* lib/erb.rb (ERB::Compiler): add instance variable @insert_cmd to
|
* lib/erb.rb (ERB::Compiler): add instance variable @insert_cmd to
|
||||||
change <%='s behavior.
|
change <%='s behavior.
|
||||||
|
|
||||||
Tue Jan 10 19:42:33 2006 Tanaka Akira <akr@m17n.org>
|
Tue Jan 10 19:42:33 2006 Tanaka Akira <akr@m17n.org>
|
||||||
|
45
object.c
45
object.c
@ -1628,22 +1628,34 @@ rb_mod_attr_accessor(int argc, VALUE *argv, VALUE klass)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* mod.const_get(sym) => obj
|
* mod.const_get(sym, inherit=true) => obj
|
||||||
*
|
*
|
||||||
* Returns the value of the named constant in <i>mod</i>.
|
* Returns the value of the named constant in <i>mod</i>.
|
||||||
*
|
*
|
||||||
* Math.const_get(:PI) #=> 3.14159265358979
|
* Math.const_get(:PI) #=> 3.14159265358979
|
||||||
|
*
|
||||||
|
* If the constant is not defined or is defined by the ancestors and
|
||||||
|
* +inherit+ is false, +NameError+ will be raised.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_mod_const_get(VALUE mod, VALUE name)
|
rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
|
||||||
{
|
{
|
||||||
ID id = rb_to_id(name);
|
VALUE name, recur;
|
||||||
|
ID id;
|
||||||
|
|
||||||
|
if (argc == 1) {
|
||||||
|
name = argv[0];
|
||||||
|
recur = Qtrue;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rb_scan_args(argc, argv, "11", &name, &recur);
|
||||||
|
}
|
||||||
|
id = rb_to_id(name);
|
||||||
if (!rb_is_const_id(id)) {
|
if (!rb_is_const_id(id)) {
|
||||||
rb_name_error(id, "wrong constant name %s", rb_id2name(id));
|
rb_name_error(id, "wrong constant name %s", rb_id2name(id));
|
||||||
}
|
}
|
||||||
return rb_const_get(mod, id);
|
return RTEST(recur) ? rb_const_get(mod, id) : rb_const_get_at(mod, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1672,23 +1684,34 @@ rb_mod_const_set(VALUE mod, VALUE name, VALUE value)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* mod.const_defined?(sym) => true or false
|
* mod.const_defined?(sym, inherit=true) => true or false
|
||||||
*
|
*
|
||||||
* Returns <code>true</code> if a constant with the given name is
|
* Returns <code>true</code> if a constant with the given name is
|
||||||
* defined by <i>mod</i>.
|
* defined by <i>mod</i>, or its ancestors if +inherit+ is not false.
|
||||||
*
|
*
|
||||||
* Math.const_defined? "PI" #=> true
|
* Math.const_defined? "PI" #=> true
|
||||||
|
* IO.const_defined? "SYNC" #=> true
|
||||||
|
* IO.const_defined? "SYNC", false #=> false
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_mod_const_defined(VALUE mod, VALUE name)
|
rb_mod_const_defined(int argc, VALUE *argv, VALUE mod)
|
||||||
{
|
{
|
||||||
ID id = rb_to_id(name);
|
VALUE name, recur;
|
||||||
|
ID id;
|
||||||
|
|
||||||
|
if (argc == 1) {
|
||||||
|
name = argv[0];
|
||||||
|
recur = Qtrue;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rb_scan_args(argc, argv, "11", &name, &recur);
|
||||||
|
}
|
||||||
|
id = rb_to_id(name);
|
||||||
if (!rb_is_const_id(id)) {
|
if (!rb_is_const_id(id)) {
|
||||||
rb_name_error(id, "wrong constant name %s", rb_id2name(id));
|
rb_name_error(id, "wrong constant name %s", rb_id2name(id));
|
||||||
}
|
}
|
||||||
return rb_const_defined_at(mod, id);
|
return RTEST(recur) ? rb_const_defined(mod, id) : rb_const_defined_at(mod, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2498,9 +2521,9 @@ Init_Object(void)
|
|||||||
rb_class_private_instance_methods, -1); /* in class.c */
|
rb_class_private_instance_methods, -1); /* 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, 0); /* in variable.c */
|
||||||
rb_define_method(rb_cModule, "const_get", rb_mod_const_get, 1);
|
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_set", rb_mod_const_set, 2);
|
||||||
rb_define_method(rb_cModule, "const_defined?", rb_mod_const_defined, 1);
|
rb_define_method(rb_cModule, "const_defined?", rb_mod_const_defined, -1);
|
||||||
rb_define_private_method(rb_cModule, "remove_const",
|
rb_define_private_method(rb_cModule, "remove_const",
|
||||||
rb_mod_remove_const, 1); /* in variable.c */
|
rb_mod_remove_const, 1); /* in variable.c */
|
||||||
rb_define_method(rb_cModule, "const_missing",
|
rb_define_method(rb_cModule, "const_missing",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user