Sha256: 8a6973da1ad45fc7fd05919bdd341afd3b3e597d32c58616f8d41d9679d90444

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

class Fancy {
  class BreakIteration : StdError {
    read_slots: ['return_value]
    def initialize: @return_value {}
  }

  class NextIteration : StdError {
    read_slots: ['return_value]
    def initialize: @return_value {}
  }

  class StopIteration : StdError {
    """
    Raised to stop the iteration, in particular by Enumerator#next.
    It is rescued by Block#loop.

    Example:
      {
        'Hello println
        StopIteration new raise!
        'World println
      } loop
      'Done! println

    Produces:

      Hello
      Done!
    """

    def initialize { @result = nil }
    def initialize: @result { }

    def result {
      """
      Returns the return value of the iterator.

        o = Object new
        def o each: block {
          block call: 1
          block call: 2
          block call: 3
          100
        }

        e = o to_enum
        e next p #=> 1
        e next p #=> 2
        e next p #=> 3
        try {
          e next
        } catch Fancy StopIteration => ex {
          ex result p #=> 100
        }
      """

      @result
    }
  }
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fancy-0.3.3 lib/iteration.fy