Sha256: 2d8a079e166e4b29fb2c1eb48f78557d9fa183e692c9735acf8b1cc24bf567ab

Contents?: true

Size: 541 Bytes

Versions: 6

Compression:

Stored size: 541 Bytes

Contents

module Enumerable
  def index_by(&block)
    return enum_for :index_by unless block_given?

    hash = Hash.new

    %x{
      var result;

      self.$each._p = function() {
        var param = #{Opal.destructure(`arguments`)},
            value = $opal.$yield1(block, param);

        if (value === $breaker) {
          result = $breaker.$v;
          return $breaker;
        }

        #{hash[`value`] = `param`};
      }

      self.$each();

      if (result !== undefined) {
        return result;
      }
    }

    hash
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
opal-activesupport-0.3.3 opal/active_support/core_ext/enumerable.rb
opal-activesupport-0.3.2 opal/active_support/core_ext/enumerable.rb
opal-activesupport-0.3.1 opal/active_support/core_ext/enumerable.rb
opal-activesupport-0.3.0 opal/active_support/core_ext/enumerable.rb
opal-activesupport-0.2.0 opal/active_support/core_ext/enumerable.rb
opal-activesupport-0.1.0 opal/active_support/core_ext/enumerable.rb