Class: LetItGo::CallerLine

Inherits:
Object
  • Object
show all
Defined in:
lib/let_it_go/caller_line.rb

Overview

Given a single line from ‘caller` retrieves line_number, file_name and can read the contents of the file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ CallerLine



6
7
8
9
10
11
12
# File 'lib/let_it_go/caller_line.rb', line 6

def initialize(string)
  file_line       = string.split(":in `".freeze).first
  file_line_array = file_line.split(":".freeze)

  @line_number = file_line_array.pop
  @file_name   = file_line_array.join(":".freeze) # name may have `:` in it
end

Instance Attribute Details

#file_nameObject

Returns the value of attribute file_name.



5
6
7
# File 'lib/let_it_go/caller_line.rb', line 5

def file_name
  @file_name
end

#line_numberObject

Returns the value of attribute line_number.



5
6
7
# File 'lib/let_it_go/caller_line.rb', line 5

def line_number
  @line_number
end

Instance Method Details

#contentsObject



14
15
16
# File 'lib/let_it_go/caller_line.rb', line 14

def contents
  @contents ||= read || ""
end