Class: Sourcify::Common::Parser::SourceCode
- Defined in:
- lib/sourcify/lib/sourcify/common/parser/source_code.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#line ⇒ Object
Returns the value of attribute line.
Instance Method Summary collapse
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file
4 5 6 |
# File 'lib/sourcify/lib/sourcify/common/parser/source_code.rb', line 4 def file @file end |
#line ⇒ Object
Returns the value of attribute line
4 5 6 |
# File 'lib/sourcify/lib/sourcify/common/parser/source_code.rb', line 4 def line @line end |
Instance Method Details
#from_file_to_s ⇒ Object
18 19 20 21 22 23 |
# File 'lib/sourcify/lib/sourcify/common/parser/source_code.rb', line 18 def from_file_to_s File.open(file, 'r') do |fh| fh.extend(File::Tail).forward(line) fh.readlines.join end end |
#from_irb_to_s ⇒ Object
25 26 27 28 29 |
# File 'lib/sourcify/lib/sourcify/common/parser/source_code.rb', line 25 def from_irb_to_s # Really owe it to Florian Groß's solution @ http://rubyquiz.com/quiz38.html ... # anyway, note that we use *line.succ* instead of *line* here. IRB.CurrentContext.io.line(line.succ .. -1).join end |
#from_pry_to_s ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sourcify/lib/sourcify/common/parser/source_code.rb', line 31 def from_pry_to_s # NOTE: HACK to reliably construct the lines required, as: # * Pry.line_buffer always fail to show the last entry # * Pry.history deliberately skips duplicated consecutive lines, # yet it reliably shows the last [ Pry.line_buffer, Pry.history.to_a[-1] ].flatten[line.succ .. -1] * "" end |
#to_s ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/sourcify/lib/sourcify/common/parser/source_code.rb', line 10 def to_s case file when /\(irb\)/, /\(irb\#\d+\)/ then from_irb_to_s when /\(pry\)/ then from_pry_to_s else from_file_to_s end end |