[#34030] Hash#select and Hash#reject bug in 1.9.2? — Lin Jen-Shin <godfat@...>
(sorry if this is a duplicated post, i forgot to subscribe)
[#34033] The rights of ruby-core people and Myth of ruby-dev — "NARUSE, Yui" <naruse@...>
Some of you may don't know your rights.
On 04/01/11 at 06:55 +0900, NARUSE, Yui wrote:
Hi,
Hi,
On Tue, Jan 04, 2011 at 06:55:47AM +0900, NARUSE, Yui wrote:
On Tue, Jan 4, 2011 at 1:57 PM, Aaron Patterson
(2011/01/05 3:57), Aaron Patterson wrote:
On Wed, Jan 05, 2011 at 01:01:48PM +0900, Urabe Shyouhei wrote:
Hi,
On Wed, Jan 5, 2011 at 6:52 PM, Shota Fukumori (sora_h)
On Thu, Jan 6, 2011 at 4:37 PM, Charles Oliver Nutter
[#34034] Exception#to_s and non-String Messages — Run Paint Run Run <runrun@...>
I don't know when Redmine will be back up, so:
[#34035] Warn when File.expand_path Ignores its Second Argument? — Run Paint Run Run <runrun@...>
File.expand_path(filename, directory) resolves _filename_ relative to
[#34043] proposal: gem_prelude needs to die — Ryan Davis <ryand-ruby@...>
I think it is time for gem_prelude to die.
2011/1/4 Ryan Davis <ryand-ruby@zenspider.com>:
2011/1/5 Ryan Davis <ryand-ruby@zenspider.com>:
On Thu, Jan 6, 2011 at 1:13 AM, Ryan Davis <ryand-ruby@zenspider.com> wrote:
FYI. JRuby 1.6RC1 is going to be shipping with RubyGems 1.4.1 and
2011/1/10 Ryan Davis <ryand-ruby@zenspider.com>:
> I'd like to drop gem_prelude down to 'require "rubygems"'. If you want, we can profile this against normal and pathological gem setups first.
[#34062] Ruby 1.9* syscall() on 64 bit systems — Niklas Hofer <niklas@...>
Hi,
[#34091] Moving to Git? — Lucas Nussbaum <lucas@...>
Hi,
> Hi,
Hello,
Em 05-01-2011 13:15, U.Nakamura escreveu:
(2011/01/06 0:46), Rodrigo Rosenfeld Rosas wrote:
> > Well, I guess I can help listing some advantages. Using git:
On Wed, Jan 5, 2011 at 11:28, Jon <jon.forums@gmail.com> wrote:
Em 05-01-2011 17:16, mathew escreveu:
On Wed, Jan 5, 2011 at 13:23, Rodrigo Rosenfeld Rosas
On Thu, Jan 06, 2011 at 06:50:24AM +0900, mathew wrote:
On Wed, Jan 5, 2011 at 17:02, Czarek <cezary.baginski@gmail.com> wrote:
On 07/01/11 at 01:05 +0900, mathew wrote:
On Thu, Jan 6, 2011 at 10:36, Lucas Nussbaum <lucas@lucas-nussbaum.net> wrote:
On 07/01/11 at 08:07 +0900, mathew wrote:
On Thu, Jan 6, 2011 at 23:50, Lucas Nussbaum <lucas@lucas-nussbaum.net> wrote:
Dear all,
Hi,
On 08/01/11 at 05:13 +0900, Ryan Davis wrote:
Hi,
What kind of Redmine integration you are talking about? We use Redmine
Hi,
Hi,
On 06-01-2011 04:06, Yukihiro Matsumoto wrote:
On Wed, Jan 5, 2011 at 19:57, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
Hi,
[#34124] [Ruby 1.9-Bug#4235][Open] svn keywords in code prevent correct building of ruby using git mirror — Stephen Bannasch <redmine@...>
Bug #4235: svn keywords in code prevent correct building of ruby using git mirror
[#34150] [Ruby 1.9-Bug#4237][Open] SSL_shutdown should be called until it returns 0 — Aaron Patterson <redmine@...>
Bug #4237: SSL_shutdown should be called until it returns 0
[#34171] [Ruby 1.8-Feature#4239][Open] Let's begin a talk for "1.8.8" -- How's needed for surviving 1.8? — Shota Fukumori <redmine@...>
Feature #4239: Let's begin a talk for "1.8.8" -- How's needed for surviving 1.8?
Issue #4239 has been updated by Zeno Davatz.
Issue #4239 has been updated by Zeno Davatz.
Issue #4239 has been updated by Zeno Davatz.
(2011/01/16 0:11), Zeno Davatz wrote:
On Sat, Jan 15, 2011 at 1:05 PM, NARUSE, Yui <naruse@airemix.jp> wrote:
(2011/01/17 1:49), Rick DeNatale wrote:
On Sun, Jan 16, 2011 at 12:19 PM, NARUSE, Yui <naruse@airemix.jp> wrote:
Issue #4239 has been updated by Zeno Davatz.
Issue #4239 has been updated by Zeno Davatz.
Hi,
[#34172] [Backport92-Backport#4240][Open] segment fault on ruby on rails project — 건하 박 <redmine@...>
Backport #4240: segment fault on ruby on rails project
[#34177] [Ruby 1.9-Bug#4241][Open] IMAPTest#test_imaps_verify_none does not stop — Kazuhiro NISHIYAMA <redmine@...>
Bug #4241: IMAPTest#test_imaps_verify_none does not stop
[#34179] Why is not git mirror mentioned in ruby downloads section? — Michal Suchanek <hramrach@...>
Hello,
On 2011-01-06 , at 07:08, Michal Suchanek wrote:
[#34214] [Ruby 1.9-Feature#4247][Open] New features for Array#sample, Array#choice — Yoji Ojima <redmine@...>
Feature #4247: New features for Array#sample, Array#choice
Hi,
On Fri, Jan 07, 2011 at 08:08:03PM +0900, Yusuke ENDOH wrote:
On 7 January 2011 18:14, Aaron Patterson <aaron@tenderlovemaking.com> wrote:
[#34244] [Ruby 1.9-Bug#4251][Open] Segmentation fault when using ruby-prof and Ruby 1.9.2 — Evan Chaney <redmine@...>
Bug #4251: Segmentation fault when using ruby-prof and Ruby 1.9.2
[#34267] [Ruby 1.9-Feature#4254][Open] Allow method transplanting — Jonas Pfenniger <redmine@...>
Feature #4254: Allow method transplanting
Wouldn't that be unnecessary if matz' trait proposal would be implemented?
2011/1/9 Haase, Konstantin <Konstantin.Haase@student.hpi.uni-potsdam.de>:
Hi,
Hi,
[#34270] Any plans for Rite and Ruby 2.0 ? — "Jonas Pfenniger (zimbatm)" <jonas@...>
Hi Matz,
[#34297] [Ruby 1.9-Bug#4255][Open] When on a case-insensitive filesystem, "loaded features" search in require should ignore case — Charles Nutter <redmine@...>
Bug #4255: When on a case-insensitive filesystem, "loaded features" search in require should ignore case
Issue #4255 has been updated by Nobuyoshi Nakada.
[#34318] ext/bigdecimal/lib/bigdecimal/util.rb — Aaron Patterson <aaron@...>
Hi Murata!
Hi,
Hi Aaron and Matz,
On Tue, Jan 11, 2011 at 01:23:47PM +0900, Kenta Murata wrote:
[#34354] [Ruby 1.9-Feature#4264][Open] General type coercion protocol for Ruby — Charles Nutter <redmine@...>
Feature #4264: General type coercion protocol for Ruby
On Tue, Jan 11, 2011 at 10:27 AM, Jim Weirich <jim.weirich@gmail.com> wrote:
On Jan 11, 2011, at 11:14 AM, Charles Oliver Nutter wrote:
Hi,
On Tue, Jan 11, 2011 at 7:18 PM, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
Issue #4264 has been updated by Charles Nutter.
On Tue, Jan 11, 2011 at 10:26, Charles Nutter <redmine@ruby-lang.org> wrote:
On 19-01-2011 08:05, mathew wrote:
Issue #4264 has been updated by Rodrigo Rosenfeld Rosas.
Both #as (Parslet, Sequel, MetaWhere, hacketyhack, Facets, Ruport, CouchPotato, ...) and #to (RSpec, Ramaze, ActiveSupport) are use in DSLs.
[#34355] [Ruby 1.9-Feature#4265][Open] Provide a core method Kernel#ruby for invoking a new Ruby instance — Charles Nutter <redmine@...>
Feature #4265: Provide a core method Kernel#ruby for invoking a new Ruby instance
> Feature #4265: Provide a core method Kernel#ruby for invoking a new Ruby instance
On Fri, Jan 14, 2011 at 9:07 AM, Roger Pack <rogerdpack2@gmail.com> wrote:
[#34416] ext/openssl development repository — Hiroshi Nakamura <nakahiro@...>
Hi, committers,
[#34483] Windows sockets and CRT fds — ghazel@...
Hi,
Hello,
On Thu, Jan 13, 2011 at 8:03 PM, U.Nakamura <usa@garbagecollect.jp> wrote:
Hello,
[#34504] [Ruby 1.9-Bug#4282][Open] Range#map inconsistency with blocks like {...} and do...end — Andrei Kulakov <redmine@...>
Bug #4282: Range#map inconsistency with blocks like {...} and do...end
[#34534] [Ruby 1.9-Bug#4283][Open] Timeout.timeout may cause application exit unintetionally — Motohiro KOSAKI <redmine@...>
Bug #4283: Timeout.timeout may cause application exit unintetionally
Issue #4283 has been updated by Charles Nutter.
Hi,
On Tue, Jan 18, 2011 at 10:00 PM, Yusuke ENDOH <mame@tsg.ne.jp> wrote:
Hi,
[#34537] [Ruby 1.9-Bug#4285][Open] Ruby don't have asynchrounous exception safe syntax and It should have. — Motohiro KOSAKI <redmine@...>
Bug #4285: Ruby don't have asynchrounous exception safe syntax and It should have.
Issue #4285 has been updated by Motohiro KOSAKI.
Hi,
Issue #4285 has been updated by Charles Nutter.
[#34550] [Ruby 1.9-Feature#4288][Open] Allow invoking arbitrary method names with foo."something" syntax — Charles Nutter <redmine@...>
Feature #4288: Allow invoking arbitrary method names with foo."something" syntax
On Wed, Jan 19, 2011 at 2:58 PM, Gary Wright <gwtmp01@mac.com> wrote:
On Wed, Jan 19, 2011 at 6:03 PM, Gary Wright <gwtmp01@mac.com> wrote:
> It does, but my concern with it is that (in the same way as
On Tue, Jan 18, 2011 at 12:51 AM, Charles Nutter <redmine@ruby-lang.org> wrote:
[#34553] Feature request - Low level bitwise operations on char arrays (or class String) — Martin Asser Hansen <mail@...>
Hello ruby-core,
Hi,
I think that the special cases of Hamming and Levensthein distances are,
What about String#bytes returning a new built-in ByteArray type
[#34558] [Ruby 1.9-Bug#4291][Open] rb_time_new with negative values (pre-epoch dates) on Windows — Kyle Banker <redmine@...>
Bug #4291: rb_time_new with negative values (pre-epoch dates) on Windows
[#34568] [PATCH] Add thread timing to Struct::Tms — Evan Phoenix <evan@...>
Because 1.9 now uses real threads, being able to find out how much time the current thread is using is quite useful, especially for benchmarking.
[#34577] Importing rubygems 1.5.0 (release candidate) into trunk. — Ryan Davis <ryand-ruby@...>
I'm going to be committing rubygems 1.5.0 into trunk in a bit.
Hi,
On Tue, Jan 18, 2011 at 11:22 PM, NARUSE, Yui <naruse@airemix.jp> wrote:
Hello,
[#34593] Autoload treatment of absolute paths in $LOAD_PATH containing . or .. — David Yip <yipdw@...>
Hello all,
[#34610] [Ruby 1.9-Bug#4294][Open] IO.popen ['"ping"', 'localhost -n 3'] fails — red stun <redmine@...>
Bug #4294: IO.popen ['"ping"', 'localhost -n 3'] fails
[#34632] Ruby operator equivalent to Groovy's "?." — Rodrigo Rosenfeld Rosas <rr.rosas@...>
One of the few things I like in Groovy that Ruby doesn't support is
I have definitely had cases where such a feature would have been very
On Thu, Jan 20, 2011 at 1:27 AM, Rodrigo Rosenfeld Rosas
Em 20-01-2011 05:35, Giuseppe Bilotta escreveu:
On Wed, Jan 19, 2011 at 6:27 PM, Rodrigo Rosenfeld Rosas
On Thu, Jan 20, 2011 at 7:01 PM, Jim Weirich <jim.weirich@gmail.com> wrote:
[#34634] Returning from the callee — Rodrigo Rosenfeld Rosas <rr.rosas@...>
Sometimes it is useful to be able to return from the callee method.
2011/1/20 Rodrigo Rosenfeld Rosas <rr.rosas@gmail.com>:
Em 20-01-2011 07:59, Jonas Pfenniger (zimbatm) escreveu:
On Thu, Jan 20, 2011 at 19:27, Rodrigo Rosenfeld Rosas
Em 20-01-2011 18:51, Nikolai Weibull escreveu:
[#34648] [Ruby 1.9-Bug#4298][Open] Duration of calling String#[] with the same index is strangely related to string length. — Radosław Bułat <redmine@...>
Bug #4298: Duration of calling String#[] with the same index is strangely related to string length.
[#34659] MRI file architecture doc — "Jonas Pfenniger (zimbatm)" <jonas@...>
Hi ruby folks,
[#34679] [Ruby 1.9-Bug#4300][Open] Merge keys not working as expected in psych yaml parser — Matthew Conway <redmine@...>
Bug #4300: Merge keys not working as expected in psych yaml parser
[#34690] [Ruby 1.9-Bug#4301][Open] Off-by-one line number in Psych parse error — Charles Nutter <redmine@...>
Bug #4301: Off-by-one line number in Psych parse error
[#34739] Redmine spam — "Jonas Pfenniger (zimbatm)" <jonas@...>
I really hate spammers, is it something we can do to prevent them
2011/1/21 Jonas Pfenniger (zimbatm) <jonas@pfenniger.name>:
[#34752] Is evaluation order of arguments specified? — Nikolai Weibull <now@...>
Is the evaluation order of arguments specified? I couldn’t find
[#34832] [Ruby 1.9-Bug#4314][Open] spwn cause Segmantation Fault if take a long string. — Motohiro KOSAKI <redmine@...>
Bug #4314: spwn cause Segmantation Fault if take a long string.
[#34861] [Ruby 1.9-Feature#4326][Open] Fiber should respond to call() and [] — Aaron Patterson <redmine@...>
Feature #4326: Fiber should respond to call() and []
Issue #4326 has been updated by Charles Nutter.
On Sat, Jan 29, 2011 at 02:58:46AM +0900, Charles Nutter wrote:
On Fri, Jan 28, 2011 at 5:29 PM, Aaron Patterson
On Sat, Jan 29, 2011 at 09:45:30AM +0900, Charles Oliver Nutter wrote:
Hi,
[#34869] make ruby support line continuations ? — Marc Chantreux <khatar@...>
hello,
You can escape line endings with backslash:
> I love it so much i tried it in ruby. trying to rewrite:
hello,
Dne 27.1.2011 7:15, Marc Chantreux napsal(a):
On Thu, Jan 27, 2011 at 04:16:50PM +0900, V咜 Ondruch wrote:
[#34888] [Ruby 1.9-Feature#4328][Open] export rb_thread_call_with_gvl() — Eric Wong <redmine@...>
Feature #4328: export rb_thread_call_with_gvl()
Hi,
SASADA Koichi <ko1@atdot.net> wrote:
[#34911] The ruby-lang.org downloads page should include RVM for OS X — Andrew Vos <andrew.vos@...>
(I sent this before I subscribed and I'm not sure if it bounced. Sorry if
RVM is not official, and makes problem more difficult. (magically
What do you mean by "official"? Also, what does it make more difficult? Do
return mail is gmail thing. I have same problem.
On Jan 27, 2011, at 5:54 PM, Shota Fukumori (sora_h) wrote:
Hi,
On Jan 27, 2011, at 7:49 PM, Shota Fukumori (sora_h) wrote:
On Fri Jan 28 2011 @ 10:57, James Edward Gray II wrote:
On Jan 27, 2011, at 8:04 PM, Peter Aronoff wrote:
[#34938] Setting libpath for AIX — Perry Smith <pedzsan@...>
Hi,
[#34959] [Ruby 1.9-Bug#4340][Open] Encoding of result string for String#gsub is not consistent — Eric Hodel <redmine@...>
Bug #4340: Encoding of result string for String#gsub is not consistent
Issue #4340 has been updated by Yui NARUSE.
Can I ask why regexps are not affected by
[#34970] [Ruby 1.9-Bug#4343][Open] Dir.glob does match files without extension — Vit Ondruch <redmine@...>
Bug #4343: Dir.glob does match files without extension
Issue #4343 has been updated by Nobuyoshi Nakada.
On 01/29/2011 10:19 AM, Nobuyoshi Nakada wrote:
Dne 29.1.2011 17:27, Jeremy Bopp napsal(a):
On 01/29/2011 10:33 AM, Vテュt Ondruch wrote:
Dne 29.1.2011 17:53, Jeremy Bopp napsal(a):
On 01/29/2011 11:09 AM, V鱈t Ondruch wrote:
On Sat, Jan 29, 2011 at 11:49, Jeremy Bopp <jeremy@bopp.net> wrote:
On 01/30/2011 06:30 PM, mathew wrote:
On Sun, Jan 30, 2011 at 23:07, Jeremy Bopp <jeremy@bopp.net> wrote:
On 02/03/2011 09:38 PM, mathew wrote:
On Thu, Feb 3, 2011 at 22:29, Jeremy Bopp <jeremy@bopp.net> wrote:
[#34991] Understanding realpath_rec behavior — Luis Lavena <luislavena@...>
Hello,
On Sun, Jan 30, 2011 at 03:01, Luis Lavena <luislavena@gmail.com> wrote:
[#35001] file_expand_path performing unneeded IO operations on native Windows — Luis Lavena <luislavena@...>
Hello,
Hello,
On Sun, Jan 30, 2011 at 9:39 PM, U.Nakamura <usa@garbagecollect.jp> wrote:
[#35010] Question: Windows versions - supported and deprecated platforms. — Luis Lavena <luislavena@...>
Hello,
Hello,
[ruby-core:34967] Re: [Ruby 1.9-Feature#3908][Assigned] private constant
Hi, matz
May I introduce these methods in relation to private constants?
- Module#public_constants, as alias to Module#constants
(corresponding to Ojbect#public_methods)
- Module#private_constants, which returns an array that contains
only private constant names.
(corresponding to Ojbect#private_methods)
- Module#public_const_get, which return the constant value or
raise a NameError if the constant is private
(corresponding to Object#public_send)
- Module#public_const_defined?, which tells whether the public
constant is defined or not
(corresponding to Module#public_method_defined?)
- Module#private_const_defined?, which tells whether the private
constant is defined or not
(corresponding to Module#private_method_defined?)
A patch and tests are attached. Thank you.
Note: I fixed other bugs which RPRR and nagachika reported (r30713,
r30714, r30715, r30716 and r30718). Sorry for late action.
2010/12/22 Yusuke Endoh <redmine@ruby-lang.org>:
> Issue #3908 has been updated by Yusuke Endoh.
>
> Status changed from Closed to Assigned
>
> Hi, NaHi
>
>> Just as a notification since I see this ticket closed today.
>
> Kazu committed a change of NEWS with ML ref, which closed this
> ticket. think that he did not intend to close this ticket.
> That is, it is just accident. 'm reopening this ticket.
>
>
>> Yusuke, patches in the mail I'm replying are not applied
>
> Yes, just because of my laziness. will work on.
>
>
>> and we still need discuss about followings, right?
>
> I think that what we needed is not discussion, but matz's final
> approval.
> The reason why this ticket stopped was because matz cancelled
> his approval and opposed this feature at [ruby-dev:42469].
> And, matz has finally re-approved it at [ruby-dev:42587].
> So we can now move on.
>
>
>> - Module#constants includes a private constant?
>
> It should not. will.
>
>
>> - Module#const_get raises NameError for a private constant?
>
> It should not. will.
>
>
>> - add Module#public_constants and Module#private_constants?
>
> Plus, Module#public_const_get. ut these may be need matz's
> additional approval.
>
>
> Matz, can I add these methods:
>
> Module#public_constants, which returns an array that contains
> nly public constant names.
>
> Module#private_constants, which returns an array that contatins
> nly private constant names.
>
> Module#public_const_get, which returns a value assigned to the
> onstant if it is public, or raise a NameError if it is private.
>
> ?
>
>
>> - Module#const_set changes the constant visibility to public? Setting
> visibility via const_set?
>
> It is just a bug. will.
>
> --
> Yusuke Endoh <mame@tsg.ne.jp>
> ----------------------------------------
> http://redmine.ruby-lang.org/issues/show/3908
>
> ----------------------------------------
> http://redmine.ruby-lang.org
--
Yusuke Endoh <mame@tsg.ne.jp>
Attachments (1)
diff --git a/include/ruby/intern.h b/include/ruby/intern.h
index 1e3a01b..5088b12 100644
--- a/include/ruby/intern.h
+++ b/include/ruby/intern.h
@@ -852,6 +852,7 @@ void *rb_mod_const_at(VALUE, void*);
void *rb_mod_const_of(VALUE, void*);
VALUE rb_const_list(void*);
VALUE rb_mod_constants(int, VALUE *, VALUE);
+VALUE rb_mod_private_constants(int, VALUE *, VALUE);
VALUE rb_mod_remove_const(VALUE, VALUE);
int rb_const_defined(VALUE, ID);
int rb_const_defined_at(VALUE, ID);
diff --git a/object.c b/object.c
index b25c0af..6856e14 100644
--- a/object.c
+++ b/object.c
@@ -1686,20 +1686,8 @@ rb_mod_attr_accessor(int argc, VALUE *argv, VALUE klass)
return Qnil;
}
-/*
- * call-seq:
- * mod.const_get(sym, inherit=true) -> obj
- *
- * Returns the value of the named constant in <i>mod</i>.
- *
- * 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
-rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
+mod_const_get(int argc, VALUE *argv, VALUE mod, VALUE visibility)
{
VALUE name, recur;
ID id;
@@ -1715,11 +1703,52 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
if (!rb_is_const_id(id)) {
rb_name_error(id, "wrong constant name %s", rb_id2name(id));
}
+ if (visibility) {
+ return RTEST(recur) ? rb_public_const_get(mod, id) : rb_public_const_get_at(mod, id);
+ }
return RTEST(recur) ? rb_const_get(mod, id) : rb_const_get_at(mod, id);
}
/*
* call-seq:
+ * mod.const_get(sym, inherit=true) -> obj
+ *
+ * Returns the value of the named constant in <i>mod</i>.
+ *
+ * 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.
+ * This method returns the value even if the constant is private.
+ */
+
+static VALUE
+rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
+{
+ mod_const_get(argc, argv, mod, FALSE);
+}
+
+/*
+ * call-seq:
+ * mod.public_const_get(sym, inherit=true) -> obj
+ *
+ * Returns the value of the named constant in <i>mod</i>.
+ *
+ * Math.public_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.
+ * +NameError+ will also be raised if the constant is private.
+ */
+
+static VALUE
+rb_mod_public_const_get(int argc, VALUE *argv, VALUE mod)
+{
+ mod_const_get(argc, argv, mod, TRUE);
+}
+
+/*
+ * call-seq:
* mod.const_set(sym, obj) -> obj
*
* Sets the named constant to the given object, returning that object.
@@ -1742,20 +1771,8 @@ rb_mod_const_set(VALUE mod, VALUE name, VALUE value)
return value;
}
-/*
- * call-seq:
- * mod.const_defined?(sym, inherit=true) -> true or false
- *
- * Returns <code>true</code> if a constant with the given name is
- * defined by <i>mod</i>, or its ancestors if +inherit+ is not false.
- *
- * Math.const_defined? "PI" #=> true
- * IO.const_defined? "SYNC" #=> true
- * IO.const_defined? "SYNC", false #=> false
- */
-
static VALUE
-rb_mod_const_defined(int argc, VALUE *argv, VALUE mod)
+mod_const_defined(int argc, VALUE *argv, VALUE mod, int visibility)
{
VALUE name, recur;
ID id;
@@ -1771,7 +1788,75 @@ rb_mod_const_defined(int argc, VALUE *argv, VALUE mod)
if (!rb_is_const_id(id)) {
rb_name_error(id, "wrong constant name %s", rb_id2name(id));
}
- return RTEST(recur) ? rb_const_defined(mod, id) : rb_const_defined_at(mod, id);
+ switch (visibility) {
+ case 0:
+ return RTEST(recur) ? rb_const_defined(mod, id) : rb_const_defined_at(mod, id);
+ case 1:
+ return RTEST(recur) ? rb_public_const_defined(mod, id) : rb_public_const_defined_at(mod, id);
+ }
+ if (RTEST(recur)) {
+ return RTEST(rb_const_defined(mod, id)) && !RTEST(rb_public_const_defined(mod, id)) ? Qtrue : Qfalse;
+ }
+ return RTEST(rb_const_defined_at(mod, id)) && !RTEST(rb_public_const_defined_at(mod, id)) ? Qtrue : Qfalse;
+}
+
+/*
+ * call-seq:
+ * mod.const_defined?(sym, inherit=true) -> true or false
+ *
+ * Returns <code>true</code> if a constant with the given name is
+ * defined by <i>mod</i>, or its ancestors if +inherit+ is not false,
+ * regardless of whether the constant is public or private.
+ *
+ * Math.const_defined? "PI" #=> true
+ * IO.const_defined? "SYNC" #=> true
+ * IO.const_defined? "SYNC", false #=> false
+ */
+
+static VALUE
+rb_mod_const_defined(int argc, VALUE *argv, VALUE mod)
+{
+ mod_const_defined(argc, argv, mod, 0);
+}
+
+/*
+ * call-seq:
+ * mod.public_const_defined?(sym, inherit=true) -> true or false
+ *
+ * Returns <code>true</code> if a public constant with the given name is
+ * defined by <i>mod</i>, or its ancestors if +inherit+ is not false.
+ *
+ * module Math
+ * private_constant :E
+ * end
+ * Math.public_const_defined? "PI" #=> true
+ * Math.public_const_defined? "E" #=> false
+ */
+
+static VALUE
+rb_mod_public_const_defined(int argc, VALUE *argv, VALUE mod)
+{
+ mod_const_defined(argc, argv, mod, 1);
+}
+
+/*
+ * call-seq:
+ * mod.private_const_defined?(sym, inherit=true) -> true or false
+ *
+ * Returns <code>true</code> if a private constant with the given name is
+ * defined by <i>mod</i>, or its ancestors if +inherit+ is not false.
+ *
+ * module Math
+ * private_constant :E
+ * end
+ * Math.private_const_defined? "PI" #=> false
+ * Math.private_const_defined? "E" #=> true
+ */
+
+static VALUE
+rb_mod_private_const_defined(int argc, VALUE *argv, VALUE mod)
+{
+ mod_const_defined(argc, argv, mod, 2);
}
VALUE rb_obj_methods(int argc, VALUE *argv, VALUE obj);
@@ -2638,9 +2723,14 @@ Init_Object(void)
rb_class_private_instance_methods, -1); /* in class.c */
rb_define_method(rb_cModule, "constants", rb_mod_constants, -1); /* in variable.c */
+ rb_define_method(rb_cModule, "public_constants", rb_mod_constants, -1); /* in variable.c */
+ rb_define_method(rb_cModule, "private_constants", rb_mod_private_constants, -1); /* in variable.c */
rb_define_method(rb_cModule, "const_get", rb_mod_const_get, -1);
+ rb_define_method(rb_cModule, "public_const_get", rb_mod_public_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);
+ rb_define_method(rb_cModule, "public_const_defined?", rb_mod_public_const_defined, -1);
+ rb_define_method(rb_cModule, "private_const_defined?", rb_mod_private_const_defined, -1);
rb_define_private_method(rb_cModule, "remove_const",
rb_mod_remove_const, 1); /* in variable.c */
rb_define_method(rb_cModule, "const_missing",
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index ce6e8a6..e58c260 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -982,8 +982,48 @@ class TestModule < Test::Unit::TestCase
assert_equal("foo", c::FOO)
end
+ module ConstTest
+ PublicConstant = :public
+ PrivateConstant = :private
+ private_constant :PrivateConstant
+ end
+
def test_constants_with_private_constant
assert(!(::TestModule).constants.include?(:PrivateClass))
+ assert_equal([:PublicConstant], ConstTest.constants)
+ end
+
+ def test_public_constants
+ assert_equal([:PublicConstant], ConstTest.public_constants)
+ end
+
+ def test_private_constants
+ assert_equal([:PrivateConstant], ConstTest.private_constants)
+ end
+
+ def test_const_defined_with_private_constant
+ assert_equal(true, ConstTest.const_defined?(:PublicConstant))
+ assert_equal(true, ConstTest.const_defined?(:PrivateConstant))
+ end
+
+ def test_public_const_defined?
+ assert_equal(true, ConstTest.public_const_defined?(:PublicConstant))
+ assert_equal(false, ConstTest.public_const_defined?(:PrivateConstant))
+ end
+
+ def test_private_const_defined?
+ assert_equal(false, ConstTest.private_const_defined?(:PublicConstant))
+ assert_equal(true, ConstTest.private_const_defined?(:PrivateConstant))
+ end
+
+ def test_const_get_with_private_constant
+ assert_equal(:public, ConstTest.const_get(:PublicConstant))
+ assert_equal(:private, ConstTest.const_get(:PrivateConstant))
+ end
+
+ def test_public_const_get
+ assert_equal(:public, ConstTest.public_const_get(:PublicConstant))
+ assert_raise(NameError) { ConstTest.public_const_get(:PrivateConstant) }
end
def test_toplevel_private_constant
diff --git a/variable.c b/variable.c
index daaf4e2..5f5b5ff 100644
--- a/variable.c
+++ b/variable.c
@@ -1742,11 +1742,11 @@ rb_mod_const_of(VALUE mod, void *data)
}
static int
-list_i(st_data_t key, st_data_t value, VALUE ary)
+list_i(st_data_t key, st_data_t value, VALUE *args)
{
ID sym = (ID)key;
rb_const_entry_t *ce = (rb_const_entry_t *)value;
- if (ce->flag != CONST_PRIVATE) rb_ary_push(ary, ID2SYM(sym));
+ if (args[1] == (ce->flag != CONST_PRIVATE)) rb_ary_push(args[0], ID2SYM(sym));
return ST_CONTINUE;
}
@@ -1754,22 +1754,52 @@ VALUE
rb_const_list(void *data)
{
st_table *tbl = data;
- VALUE ary;
+ VALUE args[2];
if (!tbl) return rb_ary_new2(0);
- ary = rb_ary_new2(tbl->num_entries);
- st_foreach_safe(tbl, list_i, ary);
+ args[0] = rb_ary_new2(tbl->num_entries);
+ args[1] = TRUE;
+ st_foreach_safe(tbl, list_i, args);
st_free_table(tbl);
- return ary;
+ return args[0];
+}
+
+static VALUE
+mod_constants(int argc, VALUE *argv, VALUE mod, VALUE visibility)
+{
+ VALUE inherit, args[2];
+ 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);
+ }
+
+ if (!tbl) return rb_ary_new2(0);
+ args[0] = rb_ary_new2(tbl->num_entries);
+ args[1] = visibility;
+ st_foreach_safe(tbl, list_i, args);
+ st_free_table(tbl);
+
+ return args[0];
}
/*
* call-seq:
* mod.constants(inherit=true) -> array
+ * mod.public_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
+ * Returns an array of the names of the public constants accessible in
+ * <i>mod</i>. This includes the names of public constants in any included
* modules (example at start of section), unless the <i>all</i>
* parameter is set to <code>false</code>.
*
@@ -1782,22 +1812,28 @@ rb_const_list(void *data)
VALUE
rb_mod_constants(int argc, VALUE *argv, VALUE mod)
{
- VALUE inherit;
- st_table *tbl;
+ return mod_constants(argc, argv, mod, TRUE);
+}
- 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);
+/*
+ * call-seq:
+ * mod.private_constants(inherit=true) -> array
+ *
+ * Returns an array of the names of the private constants accessible in
+ * <i>mod</i>. This includes the names of private constants in any included
+ * modules (example at start of section), unless the <i>all</i>
+ * parameter is set to <code>false</code>.
+ *
+ * IO.private_constants.include?(:SYNC) #=> false
+ * IO.private_constants(false).include?(:SYNC) #=> false
+ *
+ * Also see <code>Module::const_defined?</code>.
+ */
+
+VALUE
+rb_mod_private_constants(int argc, VALUE *argv, VALUE mod)
+{
+ return mod_constants(argc, argv, mod, FALSE);
}
static int