Project

General

Profile

Actions

Feature #10771

closed

An easy way to get the source location of a constant

Added by sawa (Tsuyoshi Sawada) over 6 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:67745]

Description

For constants, it is difficult to get the source location where it was (last) defined. I request either of the following to be implemented:

  • Tracepoint emits a signal when a constant is defined.
  • Implement a Constant class (similar to Method class) and a constant method (similar to method method) that behave as follows:

    foo1.rb
    1| module Foo
    2|   Bar = :bar
    3| end
    4| Foo.constant(:Bar) #=> #<Constant: Foo#Bar>
    5| Foo.constant(:Bar).source_location #=> ["foo1.rb", 2]
    
  • Implement Module#constant_source_location

    foo2.rb
    1| module Foo
    2|   Bar = :bar
    3| end
    4| Foo.constant_source_location(:Bar) #=> ["foo2.rb", 2]
    

Files

const_source_location.tar.gz (1.96 KB) const_source_location.tar.gz Patches against Ruby trunk jphelps (Jeremy Phelps), 06/26/2017 01:31 AM
Actions

Also available in: Atom PDF