Issue #14836 has been updated by joker1007 (Tomohiro Hashidate).


I want this feature too.

I wrote a rubygem that parses proc and converts to AST::Node (of ast gem).
To inspect proc source code is main purpose.

https://github.com/joker1007/proc_to_ast

Usage example.

~~~ ruby
# this is sample of rspec-parameterized gem

  describe "lambda parameter" do
    where(:a, :b, :answer) do
      [
        [1 , 2 , -> {should == 3}],
        [5 , 8 , -> {should == 13}],
        [0 , 0 , -> {should == 0}]
      ]
    end

    with_them do
      subject {a + b}
      it "should do additions" do
        self.instance_exec(&answer)
      end
    end
  end
~~~

And output example.

~~~
  lambda parameter
    a: 1, b: 2, answer: -> {should == 3}
      should do additions
    a: 5, b: 8, answer: -> {should == 13}
      should do additions
    a: 0, b: 0, answer: -> {should == 0}
      should do additions
~~~

But the gem has very heuristic hacks and it is fragile.
If multi procs exist at same line, it is very difficult to detect particular proc.
Accurate Proc location resolves the probrem.

----------------------------------------
Feature #14836: Method to return first/last lineno/column of Proc
https://bugs.ruby-lang.org/issues/14836#change-72447

* Author: tagomoris (Satoshi TAGOMORI)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
As written in https://bugs.ruby-lang.org/issues/6012, we want to know column no of Proc location.
In addition to it, I want to know the last_lineno and last_column.

If we don't have these values, we cannot know whether the "a" in code below is defined in block, or not.

```ruby
b1 = ->(){ foo() }; a = 1; b2 = ->(){ bar() }
```




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>