Module: Defly::Whinable

Defined in:
lib/defly/whinable.rb

Instance Method Summary collapse

Instance Method Details

#to_sObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/defly/whinable.rb', line 3

def to_s
  orig_message = super
  position = backtrace[0]
  message = ""
  missing_method = name.to_s
  
  unless /^\(.*\):.*/ =~ position # skipping irb
    file, line, other = position.split(':')        
    code = IO.readlines(file)[line.to_i - 1].chomp
    code.gsub!(/(#{missing_method})/, '<<\1>>')
    message = "#{file.split('/')[-1]}:#{line}> #{code}"
  end
  
  "#{orig_message}\n#{message}"
end