Class: NRSER::Meta::Source::Location
- Includes:
- Props::Immutable::Vector
- Defined in:
- lib/nrser/meta/source/location.rb
Constant Summary
Constants included from Props::Immutable::Vector
Props::Immutable::Vector::STORAGE
Class Method Summary collapse
-
.for_methods(methods, only_valid: false) ⇒ Hash<Symbol, NRSER::Meta::Source::Location>
Given an Enumerable of Method objects, return a Hash mapping their Method#name to the method’s Location.
Instance Method Summary collapse
-
#initialize(source) ⇒ Location
constructor
Override to allow argument to be ‘nil` for when Method#source_location weirdly returns `nil`.
-
#to_s ⇒ String
A short string describing the instance.
-
#valid? ⇒ Boolean
Do we have a file and a line?.
Methods included from Props::Immutable::Vector
Constructor Details
#initialize(source) ⇒ Location
Override to allow argument to be ‘nil` for when Method#source_location weirdly returns `nil`.
125 126 127 128 129 |
# File 'lib/nrser/meta/source/location.rb', line 125 def initialize source source = source.source_location if source.respond_to? :source_location source = {} if source.nil? super source end |
Class Method Details
.for_methods(methods, only_valid: false) ⇒ Hash<Symbol, NRSER::Meta::Source::Location>
We map the names instead of the Method objects themselves because aliases produce two different Method objects that ‘#==` and `#hash` the same, preventing them both from being Hash keys.
Given an Enumerable of Method objects, return a Hash mapping their Method#name to the method’s NRSER::Meta::Source::Location.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/nrser/meta/source/location.rb', line 65 def self.for_methods methods, only_valid: false all = methods.map { |method| [ method.name, NRSER::Meta::Source::Location.new( method ) ] }.to_h if only_valid all.select { |method, location| location.valid? } else all end end |
Instance Method Details
#to_s ⇒ String
Returns a short string describing the instance.
153 154 155 |
# File 'lib/nrser/meta/source/location.rb', line 153 def to_s "#{ file || '???' }:#{ line || '???' }" end |
#valid? ⇒ Boolean
Do we have a file and a line?
Sometimes ‘#source_location` gives back `nil` values or just `nil` (in which case we set both #file and #line to `nil`). I think this has to do with C extensions and other weirdness.
Anyways, this helps you handle it.
145 146 147 |
# File 'lib/nrser/meta/source/location.rb', line 145 def valid? !( file.nil? && line.nil? ) end |