core/module.rbs in rbs-1.0.0.pre vs core/module.rbs in rbs-1.0.0.pre2

- old
+ new

@@ -441,9 +441,50 @@ # # Object.const_set('foobar', 42) #=> NameError: wrong constant name foobar # def const_set: (Symbol | String arg0, untyped arg1) -> untyped + # Returns the Ruby source filename and line number containing first definition + # of 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. + # + # *inherit* specifies whether to lookup in `mod.ancestors` (`true` by default). + # + # # test.rb: + # class A + # C1 = 1 + # end + # + # module M + # C2 = 2 + # end + # + # class B < A + # include M + # C3 = 3 + # end + # + # class A # continuation of A definition + # end + # + # p B.const_source_location('C3') # => ["test.rb", 11] + # p B.const_source_location('C2') # => ["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 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 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 + # + # p Object.const_source_location('A::C1') # => ["test.rb", 2] -- nesting is supported + # p Object.const_source_location('String') # => [] -- constant is defined in C code + # + def const_source_location: (Symbol | String name, ?boolish inherit) -> ([String, Integer] | [ ] | nil) + # Returns an array of the names of the constants accessible in *mod*. This # includes the names of constants in any included modules (example at start of # section), unless the *inherit* parameter is set to `false`. # # The implementation makes no guarantees about the order in which the constants