Is it possible to retrieve more than the file and the start line of the call stack in Ruby? Consider the following model file:
# sample.rb
def sample(a = nil, b = nil, c = nil, &block)
yield if block_given?
puts caller_locations
end
sample(
1,
2,
3
)
sample do
puts "lol"
end
When executed it outputs:
$ ruby sample.rb
sample.rb:8:in '<main>'
lol
sample.rb:14:in '<main>'
But what I want is this:
$ ruby sample.rb
sample.rb:8:0-12:1:in '<main>'
lol
sample.rb:14:0-16:3:in '<main>'
It would show me line number and column ranges. Can this be done with Ruby during runtime (not using Prism or alike)?
<% line_span = yield.count("\n") + 1 %>, but this is all hacky and even wrong if the template block expanded to more HTML than there was ERB.