Class: Enumerator::Generator
- Includes:
- Enumerable
- Defined in:
- opal/opal/corelib/enumerator/generator.rb
Instance Method Summary collapse
- #each(*args, &block) ⇒ Object
-
#initialize(&block) ⇒ Generator
constructor
A new instance of Generator.
Methods included from Enumerable
#all?, #any?, #chunk, #chunk_while, #collect, #collect_concat, #compact, #count, #cycle, #detect, #drop, #drop_while, #each_cons, #each_entry, #each_slice, #each_with_index, #each_with_object, #entries, #enumerator_size, #filter_map, #find_all, #find_index, #first, #grep, #grep_v, #group_by, #include?, #inject, #lazy, #max, #max_by, #min, #min_by, #minmax, #minmax_by, #none?, #one?, #partition, #reject, #reverse_each, #slice_after, #slice_before, #slice_when, #sort, #sort_by, #sum, #take, #take_while, #tally, #to_h, #uniq, #zip
Constructor Details
#initialize(&block) ⇒ Generator
Returns a new instance of Generator.
7 8 9 10 11 12 13 |
# File 'opal/opal/corelib/enumerator/generator.rb', line 7 def initialize(&block) `$deny_frozen_access(self)` ::Kernel.raise ::LocalJumpError, 'no block given' unless block @block = block end |
Instance Method Details
#each(*args, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'opal/opal/corelib/enumerator/generator.rb', line 15 def each(*args, &block) yielder = Yielder.new(&block) %x{ try { args.unshift(#{yielder}); Opal.yieldX(#{@block}, args); } catch (e) { if (e && e.$thrower_type == "breaker") { return e.$v; } else { throw e; } } } self end |