Class: Sourcify::Proc::Parser::SourceCode
- Inherits:
-
Struct
- Object
- Struct
- Sourcify::Proc::Parser::SourceCode
- Defined in:
- lib/sourcify/proc/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/proc/parser/source_code.rb', line 4 def file @file end |
#line ⇒ Object
Returns the value of attribute line
4 5 6 |
# File 'lib/sourcify/proc/parser/source_code.rb', line 4 def line @line end |
Instance Method Details
#from_file_to_s ⇒ Object
17 18 19 20 21 22 |
# File 'lib/sourcify/proc/parser/source_code.rb', line 17 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
24 25 26 27 28 |
# File 'lib/sourcify/proc/parser/source_code.rb', line 24 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 |
#to_s ⇒ Object
10 11 12 13 14 15 |
# File 'lib/sourcify/proc/parser/source_code.rb', line 10 def to_s case file when /\(irb\)/ then from_irb_to_s else from_file_to_s end end |