Skip to content

Instantly share code, notes, and snippets.

@lukas2
Created September 22, 2014 08:25
Show Gist options
  • Save lukas2/c283fddad5d6883efee6 to your computer and use it in GitHub Desktop.
Save lukas2/c283fddad5d6883efee6 to your computer and use it in GitHub Desktop.

Revisions

  1. lukas2 created this gist Sep 22, 2014.
    14 changes: 14 additions & 0 deletions divide by zero
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@

    class Fixnum
    alias_method :_div, :/
    def /(a)
    if a == 0
    0
    else
    _div a
    end
    end
    end

    puts "9 / 2 = %f" % (9 / 2).to_f
    puts "9 / 0 = %f" % (9 / 0).to_f