aboutsummaryrefslogtreecommitdiffstats
path: root/object.c
diff options
context:
space:
mode:
authorzverok <zverok.offline@gmail.com>2020-01-19 13:49:15 +0200
committerJeremy Evans <code@jeremyevans.net>2020-01-23 09:22:38 -0800
commit2bde7919a0a8302c344e9bb9ddc217958fcbd3c7 (patch)
tree3801db98af061da06aa2218f348da9aa69190bcc /object.c
parent109183c2c0902a0af735b2660737e1724307b264 (diff)
downloadruby-2bde7919a0a8302c344e9bb9ddc217958fcbd3c7.tar.gz
Clarify const_source_location docs
Diffstat (limited to 'object.c')
-rw-r--r--object.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/object.c b/object.c
index 166fdae7e1..8acb80c35e 100644
--- a/object.c
+++ b/object.c
@@ -2762,8 +2762,8 @@ rb_mod_const_defined(int argc, VALUE *argv, VALUE mod)
* mod.const_source_location(sym, inherit=true) -> [String, Integer]
* mod.const_source_location(str, inherit=true) -> [String, Integer]
*
- * Returns the Ruby source filename and line number containing first definition
- * of constant specified. If the named constant is not found, +nil+ is returned.
+ * Returns the Ruby source filename and line number containing the definition
+ * of the constant specified. If the named constant is not found, +nil+ is returned.
* If the constant is found, but its source location can not be extracted
* (constant is defined in C code), empty array is returned.
*
@@ -2773,28 +2773,32 @@ rb_mod_const_defined(int argc, VALUE *argv, VALUE mod)
* # test.rb:
* class A
* C1 = 1
+ * C2 = 2
* end
*
* module M
- * C2 = 2
+ * C3 = 3
* end
*
* class B < A
* include M
- * C3 = 3
+ * C4 = 4
* end
*
* class A # continuation of A definition
+ * C2 = 8 # constant redefinition; warned yet allowed
* end
*
- * p B.const_source_location('C3') # => ["test.rb", 11]
- * p B.const_source_location('C2') # => ["test.rb", 6]
+ * p B.const_source_location('C4') # => ["test.rb", 11]
+ * p B.const_source_location('C3') # => ["test.rb", 6]
* p B.const_source_location('C1') # => ["test.rb", 2]
*
- * p B.const_source_location('C2', false) # => nil -- don't lookup in ancestors
+ * p B.const_source_location('C3', false) # => nil -- don't lookup in ancestors
+ *
+ * p A.const_source_location('C2') # => ["test.rb", 16] -- actual (last) definition place
*
- * p Object.const_source_location('B') # => ["test.rb", 9]
- * p Object.const_source_location('A') # => ["test.rb", 1] -- note it is first entry, not "continuation"
+ * p Object.const_source_location('B') # => ["test.rb", 9] -- top-level constant could be looked through Object
+ * p Object.const_source_location('A') # => ["test.rb", 1] -- class reopening is NOT considered new definition
*
* p B.const_source_location('A') # => ["test.rb", 1] -- because Object is in ancestors
* p M.const_source_location('A') # => ["test.rb", 1] -- Object is not ancestor, but additionally checked for modules