Class: Enumerator::Generator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
opal/opal/corelib/enumerator.rb

Instance Method Summary collapse

Methods included from Enumerable

#all?, #any?, #chunk, #chunk_while, #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, #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, #uniq, #zip

Constructor Details

#initialize(&block) ⇒ Generator

Returns a new instance of Generator

Raises:



94
95
96
97
98
# File 'opal/opal/corelib/enumerator.rb', line 94

def initialize(&block)
  raise LocalJumpError, 'no block given' unless block

  @block = block
end

Instance Method Details

#each(*args, &block) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'opal/opal/corelib/enumerator.rb', line 100

def each(*args, &block)
  yielder = Yielder.new(&block)

  %x{
    try {
      args.unshift(#{yielder});

      Opal.yieldX(#@block, args);
    }
    catch (e) {
      if (e === $breaker) {
        return $breaker.$v;
      }
      else {
        throw e;
      }
    }
  }

  self
end