Class: ErrorRescue
- Inherits:
-
Object
- Object
- ErrorRescue
- Defined in:
- lib/snorkel.rb
Instance Method Summary collapse
- #ask_response ⇒ Object
- #find_line ⇒ Object
-
#initialize(file) ⇒ ErrorRescue
constructor
A new instance of ErrorRescue.
- #launch_search ⇒ Object
- #track_method ⇒ Object
Constructor Details
#initialize(file) ⇒ ErrorRescue
Returns a new instance of ErrorRescue.
5 6 7 8 9 10 11 |
# File 'lib/snorkel.rb', line 5 def initialize(file) @file = File.open(file, "rb") @file_name = file @message = nil track_method ask_response end |
Instance Method Details
#ask_response ⇒ Object
30 31 32 33 34 35 |
# File 'lib/snorkel.rb', line 30 def ask_response puts "On line #{find_line[1]} of #{@file_name}: #{@message.capitalize}".blue puts "Would you like to search your error?" @response = $stdin.gets.chomp launch_search end |
#find_line ⇒ Object
23 24 25 26 27 28 |
# File 'lib/snorkel.rb', line 23 def find_line @line.map do |e| e.match(/^(.+?):(\d+)(|:in `(.+)')$/) $2 end end |
#launch_search ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/snorkel.rb', line 37 def launch_search = @message.split(" ").join("+").downcase if @response.start_with? 'y' Launchy.open("https://www.google.com/#q=#{}+ruby") else puts "Have a nice day!" end end |
#track_method ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/snorkel.rb', line 13 def track_method begin eval(@file.read) rescue => ex @message = ex. @line = ex.backtrace end return if @message == nil end |