Repository navigation
Open
Description
This is a test case to demonstrate what I mentioned in the title:
#!/usr/bin/env ruby
# test.rb
class TestClass
source = <<-EOF
def test_m
"test_m here"
end
EOF
eval(source)
end[1] pry(main)> require './test.rb'
=> true
[2] pry(main)> TestClass.new.test_m
=> "test_m here"
[3] pry(main)> m = TestClass.new.method :test_m
=> #<Method: TestClass#test_m>
[4] pry(main)> m.source
MethodSource::SourceNotFoundError: Could not load source for : No such file or directory @ rb_sysopen - (eval)
from /home/yanying/.rvm/gems/ruby-2.1.5/gems/method_source-0.8.2/lib/method_source.rb:55:in `rescue in lines_for'
[5] pry(main)> m.source_location
=> ["(eval)", 1]
[6] pry(main)> Metadata
Metadata
Assignees
Labels
No labels
Activity
kyrylo commentedon Nov 11, 2015
There's no way to read source code from
eval.mvz commentedon May 4, 2016
The live_ast gem does something like this. Here's a quick proof-of-concept to work with method_source:
A real implementation would need to override
evaland usebinding_of_callerto automate this.