Skip to content

Instantly share code, notes, and snippets.

@ksss
Created May 31, 2016 08:41
Show Gist options
  • Save ksss/12cb7c08a41c8de8190e69ecbb6d4315 to your computer and use it in GitHub Desktop.
Save ksss/12cb7c08a41c8de8190e69ecbb6d4315 to your computer and use it in GitHub Desktop.
$ ruby pretty-argumenterror.rb
ArgumentError: wrong number of arguments (given 3, expected 2)
from: pretty-argumenterror.rb
1 | #! /usr/bin/env ruby
2 |
-> 3 | def foo(a, b)
4 | end
5 |
6 | begin
#! /usr/bin/env ruby
def foo(a, b)
end
begin
foo(1, 2, 3)
rescue => e
m = /(?<filename>.*?):(?<lineno>\d+):in\s`(?<method>.*)'/.match(e.backtrace.first)
lineno = m["lineno"].to_i - 3
puts "#{e.class}: #{e.message}"
puts "from: #{m["filename"]}"
IO.foreach(m["filename"]).to_a[lineno, 6].each_with_index do |line, index|
n = lineno + index + 1
puts " #{n == m["lineno"].to_i ? "->" : " "} #{n} | #{line}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment