返回顶部

收藏

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

»更多 您可能感兴趣的代码
  1. 2016-02-09 11:56:59use curly braces ({}): by Loli控
  2. 2016-02-17 20:44:19The if Statement with constant by Jamin
  3. 2016-03-29 16:55:30Nested for loop by 杨洋
  4. 2016-09-06 17:58:38general form of the for loop by Loli控
  5. 2016-09-06 20:50:38throw sends a message to catch if n is less than or equal to 0. by Loli控
  6. 2016-09-07 11:14:26do all the times tables from 1 to 12 by LeoSun
  7. 2016-11-01 09:24:09If vs Case by digua
  8. 2015-12-06 17:14:38All Ruby expressions return a result by 胡晋
  9. 2016-03-02 11:18:28nest if logic by jeffsui
  10. 2016-09-06 18:18:46For each item in by 杨洋
  11. 2016-09-06 21:11:42basic way to implement a loop by Ω油菜

发表评论