class SourceCode::Method
Attributes
source_location[R]
Public Class Methods
new(source_location)
click to toggle source
# File lib/source_code/method.rb, line 7 def initialize source_location @source_location = source_location end
Public Instance Methods
source_code()
click to toggle source
# File lib/source_code/method.rb, line 11 def source_code lines[first_line...last_line].join end
Private Instance Methods
file()
click to toggle source
# File lib/source_code/method.rb, line 17 def file source_location[0] end
first_line()
click to toggle source
# File lib/source_code/method.rb, line 25 def first_line source_location[1] - 1 end
indentation_on(line_number)
click to toggle source
# File lib/source_code/method.rb, line 38 def indentation_on line_number lines[line_number].length - lines[line_number].lstrip.length end
last_line()
click to toggle source
# File lib/source_code/method.rb, line 29 def last_line index = first_line loop do index += 1 break unless indentation_on(first_line) != indentation_on(index) end index + 1 end
lines()
click to toggle source
# File lib/source_code/method.rb, line 21 def lines @lines ||= File.read(file).lines end