Defly
- 2. Andrew Liu
• Collage Student
• Intern @ Cardinalblue
• eggegg @ github
• Ruby, iOS, Android
• andrewliu33@gmail.com
- 4. Defly is for...
• Trace method calls
• Trace instance variables
• Better error messages
• Inspect the point of error
- 5. class Warrior
attr_accessor :hp, :mp
def sleep
self.hp += 10
self.mp += 2
end
end
- 6. class Warrior
attr_accessor :hp, :mp
def sleep
puts "BEFORE: #{@hp}, #{@mp}"
self.hp += 10
puts "AFTER ADDING HP: #{@hp}, #{@mp}"
self.mp += 2
puts "AFTER ADDING MP: #{@hp}, #{@mp}"
end
end
- 7. class Warrior
attr_accessor :hp, :mp
def sleep
self.hp += 10
self.mp += 2
end
end
require 'defly'
Warrior.debug!
Warrior.new.trace([:hp, :hp=, :mp, :mp=, :sleep],
[:@hp, :@mp]) do |warrior|
warrior.hp = 10
warrior.mp = 20
warrior.sleep
end
- 8. Tracing hp, hp=, mp, mp=, sleep on Warrior instance
Tracing @hp, @mp on Warrior instance
<<<<< Warrior#hp=(10) # (irb):14:in `block in irb_binding'
@hp = 10 # undefined
@mp = nil # undefined
>>>>> 10
<<<<< Warrior#mp=(20) # (irb):15:in `block in irb_binding'
@mp = 20 # undefined
>>>>> 20
<<<<< Warrior#sleep() # (irb):16:in `block in irb_binding'
<<<<< Warrior#hp() # (irb):7:in `sleep'
>>>>> 10
<<<<< Warrior#hp=(20) # (irb):7:in `sleep'
@hp = 20 # 10 -> 20
>>>>> 20
<<<<< Warrior#mp() # (irb):8:in `sleep'
>>>>> 20
<<<<< Warrior#mp=(22) # (irb):8:in `sleep'
@mp = 22 # 20 -> 22
>>>>> 22
>>>>> 22
- 9. NoMethodError
bug.rb
debugging = nil
debugging.is_annoying
irb
irb(main):001:0> require 'bug'
NoMethodError: undefined method `is_annoying' for nil:NilClass
from /Users/eggegg/bug.rb:2:in `<top (required)>'
...
Where is the bug???
- 10. irb(main):003:0> require 'defly'
=> true
irb(main):004:0> require 'bug'
NoMethodError: undefined method `is_annoying' for nil:NilClass
bug.rb:2> debugging.<<is_annoying>>
from /Users/andrewliu/bug.rb:2:in `<top (required)>'
- 11. Inspecting Errors
class Rocket
def launch!
@reason = "Bugs invasion"
raise "Engine Fail"
end
end
Rocket.debug!
rocket = Rocket.new
rocket.watch_error "Engine Fail"
rocket.launch!
- 12. Ruby shell (Rib by godfat)
to inspect errors!
>>>>> Error received:
"Engine Fail"
>>>>>
#<Rocket:0(0)>> @reason
=> "Bugs invasion"
#<Rocket:0(0)>>
Editor's Notes
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n