Class: RubyJS.Range

Defined in: lib/corelib/range.coffee
Inherits: RubyJS.Object
Includes: RubyJS.Enumerable

Overview

R.Range.new()

Class Method Summary

Instance Method Summary

Inherited Method Summary

Methods inherited from RubyJS.Object

.include, .__add_default_aliases__, #send, #respond_to, #to_enum, #tap

Included Method Summary

Methods included from RubyJS.Enumerable

Class Method Details

+ (void) new(start, end, exclusive = false)

TODO: .new should BOX here:

Constructor Details

- (void) constructor(start, end, exclusive = false)

TODO: do not box here...

Instance Method Details

- (void) '=='(other)

- (?) begin(obj)

Returns the first object in rng

Returns:

  • (?) — obj

- (void) cover(obj)

Returns true if obj is between beg and end, i.e beg <= obj <= end (or end exclusive when exclude_end? is true).

R.rng("a", "z").cover("c")    #=> true
R.rng("a", "z").cover("5")    #=> false

@param other

- (void) '==='(other)

- (Range, Enumerator) each(block)

TODO: Untested single_block_args

Iterates over the elements rng, passing each in turn to the block. You can only iterate if the start object of the range supports the succ method (which means that you can’t iterate over ranges of Float objects).

If no block is given, an enumerator is returned instead.

R.rng(10, 15).each (n) ->
   console.log n, ' '

# 10 11 12 13 14 15

Returns:

  • Range, Enumerator

- (?) end()

Returns the object that defines the end of rng.

R.rng(1,10).end()        #=> 10
R.rng(1,10, true).end()  #=> 10

Returns:

  • (?) — obj

- (true, false) exclude_end()

Returns true if rng excludes its end value.

Returns:

  • true, false

- (obj, Array<obj>) first(n)

TODO:

first(n) not yet implemented

Returns the first object in rng, or the first n elements.

Returns:

  • obj, Array<obj>

- (String) inspect()

Convert this range object to a printable form (using inspect to convert the start and end objects).

Returns:

  • String

- (void) min(block)

min → obj
min {| a,b | block } → obj

Returns the minimum value in rng. The second uses the block to compare values. Returns nil if the first value in range is larger than the last value

- (?) max(block)

Returns the maximum value in rng. The second uses the block to compare values. Returns nil if the first value in range is larger than the last value.

Returns:

  • (?) — obj

- (void) start()

- (Range, Enumerator) step(step_size = 1, block)

TODO: fix imprecision when using floats as step_sizes

Iterates over rng, passing each nth element to the block. If the range contains numbers, n is added for each iteration. Otherwise step invokes succ to iterate through range elements. The following code uses class Xs, which is defined in the class-level documentation.

If no block is given, an enumerator is returned instead.

R.rng('a', 'f').step(2, (x) -> puts x) # => a c e R.rng('a', 'f').step(3).to_a() # => [a, d]

Returns:

  • (Range, Enumerator) — returns self or Enumerator if no block given.

- (void) to_a()