[前][次][番号順一覧][スレッド一覧]

ruby-changes:36239

From: eregon <ko1@a...>
Date: Sun, 9 Nov 2014 01:54:28 +0900 (JST)
Subject: [ruby-changes:36239] eregon:r48320 (trunk): * object.c (Module#const_defined?): [DOC] Revise the documentation.

eregon	2014-11-09 01:54:15 +0900 (Sun, 09 Nov 2014)

  New Revision: 48320

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48320

  Log:
    * object.c (Module#const_defined?): [DOC] Revise the documentation.
      Patch by Xavier Noria.
      [Fixes GH-754] https://github.com/ruby/ruby/pull/754

  Modified files:
    trunk/ChangeLog
    trunk/object.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48319)
+++ ChangeLog	(revision 48320)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Nov  9 01:51:50 2014  Benoit Daloze  <eregontp@g...>
+
+	* object.c (Module#const_defined?): [DOC] Revise the documentation.
+	  Patch by Xavier Noria.
+	  [Fixes GH-754] https://github.com/ruby/ruby/pull/754
+
 Sun Nov  9 00:37:44 2014  Tanaka Akira  <akr@f...>
 
 	* test/webrick: Examine log and use assert_join_threads.
Index: object.c
===================================================================
--- object.c	(revision 48319)
+++ object.c	(revision 48320)
@@ -2221,20 +2221,39 @@ rb_mod_const_set(VALUE mod, VALUE name, https://github.com/ruby/ruby/blob/trunk/object.c#L2221
  *     mod.const_defined?(sym, inherit=true)   -> true or false
  *     mod.const_defined?(str, inherit=true)   -> true or false
  *
- *  Checks for a constant with the given name in <i>mod</i>
- *  If +inherit+ is set, the lookup will also search
- *  the ancestors (and +Object+ if <i>mod</i> is a +Module+.)
+ *  Says whether _mod_ or its ancestors have a constant with the given name:
  *
- *  Returns whether or not a definition is found:
+ *    Float.const_defined?(:EPSILON)      #=> true, found in Float itself
+ *    Float.const_defined?("String")      #=> true, found in Object (ancestor)
+ *    BasicObject.const_defined?(:Hash)   #=> false
  *
- *     Math.const_defined? "PI"   #=> true
- *     IO.const_defined? :SYNC   #=> true
- *     IO.const_defined? :SYNC, false   #=> false
+ *  If _mod_ is a +Module+, additionally +Object+ and its ancestors are checked:
  *
- *  If neither +sym+ nor +str+ is not a valid constant name a NameError will be
- *  raised with a warning "wrong constant name".
+ *    Math.const_defined?(:String)   #=> true, found in Object
  *
- *	Hash.const_defined? 'foobar' #=> NameError: wrong constant name foobar
+ *  In each of the checked classes or modules, if the constant is not present
+ *  but there is an autoload for it, +true+ is returned directly without
+ *  autoloading:
+ *
+ *    module Admin
+ *      autoload :User, 'admin/user'
+ *    end
+ *    Admin.const_defined?(:User)   #=> true
+ *
+ *  If the constant is not found the callback +const_missing+ is *not* called
+ *  and the method returns +false+.
+ *
+ *  If +inherit+ is false, the lookup only checks the constants in the receiver:
+ *
+ *    IO.const_defined?(:SYNC)          #=> true, found in File::Constants (ancestor)
+ *    IO.const_defined?(:SYNC, false)   #=> false, not found in IO itself
+ *
+ *  In this case, the same logic for autoloading applies.
+ *
+ *  If the argument is not a valid constant name +NameError+ is raised with the
+ *  message "wrong constant name _name_":
+ *
+ *    Hash.const_defined? 'foobar'   #=> NameError: wrong constant name foobar
  *
  */
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]