Class: Ruby2JS::OpalEnumerator

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby2js/jsx.rb

Overview

Opal’s enumerator doesn’t currently support next and peek methods. Build a wrapper that adds those methods.

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ OpalEnumerator

Returns a new instance of OpalEnumerator.



295
296
297
# File 'lib/ruby2js/jsx.rb', line 295

def initialize(stream)
  @stream = stream.to_a
end

Instance Method Details

#nextObject

Raises:

  • (StopIteration)


299
300
301
302
# File 'lib/ruby2js/jsx.rb', line 299

def next
  raise StopIteration.new if @stream.empty?
  @stream.shift
end

#peekObject

Raises:

  • (StopIteration)


304
305
306
307
# File 'lib/ruby2js/jsx.rb', line 304

def peek
  raise StopIteration.new if @stream.empty?
  @stream.first
end