返回顶部

收藏

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

标签:Ruby,Statement

收藏

0人收藏

支持

0

反对

0

发表评论