Class: RubyJS.Breaker

Defined in: lib/corelib/breaker.coffee

Overview

Breaker is a R class for adding support to breaking out of functions that act like loops. Because we mimick ruby block/procs/lambdas by passing functions, so neither break nor return would work in JS.

Examples:

Breaking loops

 sum = R('')
 R.catch_break( breaker ) -> # breaker is a new Breaker instance
   R('a').upto('f') (chr) ->
     breaker.break() if chr.equals('d')
     sum.append(chr)
 # => 'abc'

Breaking out and return a value

 R.catch_break( breaker ) -> # breaker is a new Breaker instance
   R(1).upto(100) (i) ->
     breaker.break('foo') if i.equals(81)
 # => 'foo'

See also:

Instance Method Summary

Constructor Details

- (void) constructor(return_value = null, broken = false)

Instance Method Details

- (void) break(return_value)

Breaks out of the loop by throwing itself. Accepts a return value.

@param value Return value

Examples:

Breaking out and return a value

   R.catch_break( breaker )
     breaker.break('foo')
   # => 'foo'

- (void) handle_break(e)