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

ruby-changes:59788

From: zverok <ko1@a...>
Date: Fri, 24 Jan 2020 02:22:58 +0900 (JST)
Subject: [ruby-changes:59788] 2bde7919a0 (master): Clarify const_source_location docs

https://git.ruby-lang.org/ruby.git/commit/?id=2bde7919a0

From 2bde7919a0a8302c344e9bb9ddc217958fcbd3c7 Mon Sep 17 00:00:00 2001
From: zverok <zverok.offline@g...>
Date: Sun, 19 Jan 2020 13:49:15 +0200
Subject: Clarify const_source_location docs


diff --git a/object.c b/object.c
index 166fdae..8acb80c 100644
--- a/object.c
+++ b/object.c
@@ -2762,8 +2762,8 @@ rb_mod_const_defined(int argc, VALUE *argv, VALUE mod) https://github.com/ruby/ruby/blob/trunk/object.c#L2762
  *     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) https://github.com/ruby/ruby/blob/trunk/object.c#L2773
  *      # 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
-- 
cgit v0.10.2


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

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