Defly

 Defly

A debug tool for Ruby

B445ebf67c71d53b0b3bbe6d9bddd1c3?s=128

Andrew Liu

August 27, 2011
Tweet

Transcript

  1. 2.

    Andrew Liu 劉彥廷 • College Student • Intern @ Cardinalblue

    • eggegg @ github • Ruby, iOS, Android • andrewliu33@gmail.com
  2. 4.

    Defly is for... • Trace method calls • Trace instance

    variables • Better error messages • Inspect the point of error
  3. 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
  4. 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
  5. 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
  6. 9.

    NoMethodError debugging = nil debugging.is_annoying irb(main):001:0> require 'bug' NoMethodError: undefined

    method `is_annoying' for nil:NilClass from /Users/eggegg/bug.rb:2:in `<top (required)>' ... bug.rb irb Where is the bug???
  7. 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)>'
  8. 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!
  9. 12.

    >>>>> Error received: "Engine Fail" >>>>> #<Rocket:0(0)>> @reason => "Bugs

    invasion" #<Rocket:0(0)>> Ruby shell (Rib by godfat) to inspect errors!