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.



297
298
299
# File 'lib/ruby2js/jsx.rb', line 297

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

Instance Method Details

#nextObject

Raises:

  • (StopIteration)


301
302
303
304
# File 'lib/ruby2js/jsx.rb', line 301

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

#peekObject

Raises:

  • (StopIteration)


306
307
308
309
# File 'lib/ruby2js/jsx.rb', line 306

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