Class: GG::StackLine
Overview
Represents one item in the callstack returned by the Kernel#caller method. This is a better representation because it parses out the #dir, #path, #code and other pieces of the callstack item.
Instance Attribute Summary collapse
-
#line_number ⇒ Object
readonly
Returns the value of attribute line_number.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#value ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #code_line ⇒ Object
- #code_lines ⇒ Object
-
#dir ⇒ Object
Returns the directory of the StackLine.
-
#initialize(s) ⇒ StackLine
constructor
Takes a string from the array of strings returned from Ruby’s method Kernel#caller.
-
#join(subpath) ⇒ Object
Joins the directory of the stakk item with the given subpath.
Constructor Details
#initialize(s) ⇒ StackLine
Takes a string from the array of strings returned from Ruby’s method Kernel#caller.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gg/stack_line.rb', line 9 def initialize( s ) matchdata = /^(.*)[:]([0-9]+)(?:[:]in `(.*)')?$/.match( s ) # If the line in caller can be parsed, then set the correct instance vars if matchdata @path = File.( matchdata[1] ) @line_number = matchdata[2].to_i @method_name = matchdata[3] ? matchdata[3].to_sym : nil # If there is no proper match, we just set all the values to nil. # Technically this isn't required but it makes for clearer intent here. :) else @path = nil @line = nil @method_name = nil end @value = s end |
Instance Attribute Details
#line_number ⇒ Object (readonly)
Returns the value of attribute line_number.
26 27 28 |
# File 'lib/gg/stack_line.rb', line 26 def line_number @line_number end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
26 27 28 |
# File 'lib/gg/stack_line.rb', line 26 def method_name @method_name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
26 27 28 |
# File 'lib/gg/stack_line.rb', line 26 def path @path end |
#value ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute value.
26 27 28 |
# File 'lib/gg/stack_line.rb', line 26 def value @value end |
Instance Method Details
#code_line ⇒ Object
32 33 34 |
# File 'lib/gg/stack_line.rb', line 32 def code_line code_lines[ line_number-1 ] end |
#code_lines ⇒ Object
28 29 30 |
# File 'lib/gg/stack_line.rb', line 28 def code_lines @code_lines ||= File.readlines( path ) end |
#dir ⇒ Object
Returns the directory of the StackLine
37 38 39 |
# File 'lib/gg/stack_line.rb', line 37 def dir File.dirname( path ) end |
#join(subpath) ⇒ Object
Joins the directory of the stakk item with the given subpath
42 43 44 |
# File 'lib/gg/stack_line.rb', line 42 def join( subpath ) File.join( dir, subpath ) end |