Raise IndexError : raise « Statement « Ruby






Raise IndexError


  class MyCapacity
    include Comparable

    attr :volume

    def initialize(volume)
      @volume = volume
    end

    def inspect
      '#' * @volume
    end

    def <=>(other)
      self.volume <=> other.volume
    end

    def succ
      raise(IndexError, "Volume too big") if @volume >= 9
      MyCapacity.new(@volume.succ)
    end
  end

 








Related examples in the same category

1.Raising Exceptions
2.Raise exception from constructor
3.raise one on your own with the raise method from Kernel
4.raise ArgumentError