Class: Enumerator::Yielder

Inherits:
Object show all
Defined in:
opal/opal/corelib/enumerator/yielder.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Yielder

Returns a new instance of Yielder.



3
4
5
6
7
8
# File 'opal/opal/corelib/enumerator/yielder.rb', line 3

def initialize(&block)
  @block = block
  # rubocop:disable Lint/Void
  self
  # rubocop:enable Lint/Void
end

Instance Method Details

#<<(value) ⇒ Object



22
23
24
25
26
# File 'opal/opal/corelib/enumerator/yielder.rb', line 22

def <<(value)
  self.yield(value)

  self
end

#to_procObject



28
29
30
31
32
# File 'opal/opal/corelib/enumerator/yielder.rb', line 28

def to_proc
  proc do |*values|
    self.yield(*values)
  end
end

#yield(*values) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'opal/opal/corelib/enumerator/yielder.rb', line 10

def yield(*values)
  %x{
    var value = Opal.yieldX(#{@block}, values);

    if (value && value.$thrower_type == "break") {
      throw value;
    }

    return value;
  }
end