Module: FileLine

Defined in:
lib/file_line.rb

Overview

for pry Pry.current_line Pry::VERSION puts “Pry.history.to_a:”, Pry.history.to_a puts “Pry.current_line:”, Pry.current_line puts “Pry.current.eval_string:”, Pry.current.eval_string puts “Pry.line_buffer.last:”, Pry.line_buffer.last puts “Pry.line_buffer:”, Pry.line_buffer

Class Method Summary collapse

Class Method Details

.get(file_path, line_no) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/file_line.rb', line 11

def self.get(file_path, line_no)
    # only test for Pry::VERSION == 0.10.0
    if file_path == "(pry)"
        return Pry.history.to_a.last
    end
    if file_path == "(irb)"
        return Readline::HISTORY.to_a.last
    end
    open(file_path) do |f|
        # tap depend on ruby > 1.9
        return f.each_line.tap{|enum| (line_no-1).times{enum.next}}.next
    end
end