Class: Enumerator::Generator
- Includes:
- Enumerable
- Defined in:
- opal/opal/corelib/enumerator.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, #collect, #collect_concat, #count, #cycle, #detect, #drop, #drop_while, #each_cons, #each_entry, #each_slice, #each_with_index, #each_with_object, #entries, #enumerator_size, #find_all, #find_index, #first, #grep, #group_by, #include?, #inject, #lazy, #max, #max_by, #min, #min_by, #minmax, #minmax_by, #none?, #one?, #partition, #reject, #reverse_each, #slice_before, #sort, #sort_by, #take, #take_while, #zip
Constructor Details
#initialize(&block) ⇒ Generator
Returns a new instance of Generator
105 106 107 108 109 |
# File 'opal/opal/corelib/enumerator.rb', line 105 def initialize(&block) raise LocalJumpError, 'no block given' unless block @block = block end |
Instance Method Details
#each(*args, &block) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'opal/opal/corelib/enumerator.rb', line 111 def each(*args, &block) yielder = Yielder.new(&block) %x{ try { args.unshift(#{yielder}); if (Opal.yieldX(#@block, args) === $breaker) { return $breaker.$v; } } catch (e) { if (e === $breaker) { return $breaker.$v; } else { throw e; } } } self end |