Sha256: 7941367643c49146d7fe6ca36b41449006808befa79f1a10853937548a43d05f

Contents?: true

Size: 1.08 KB

Versions: 19

Compression:

Stored size: 1.08 KB

Contents

# Must be defined outside of Kernel for jruby, see http://jira.codehaus.org/browse/JRUBY-3609
Enumerator = Enumerable::Enumerator unless Object.const_defined? :Enumerator # Standard in ruby 1.9

class Enumerator
  # new with block, standard in Ruby 1.9
  unless (self.new{} rescue false)
      # A simple class which allows the construction of Enumerator from a block
    class Yielder
      def initialize(&block)
        @main_block = block
      end

      def each(&block)
        @final_block = block
        @main_block.call(self)
      end

      def yield(*arg)
        @final_block.yield(*arg)
      end

      def <<(*arg)
        @final_block.yield(*arg)
        self
      end
    end

    def initialize_with_optional_block(*arg, &block)
      return initialize_without_optional_block(*arg, &nil) unless arg.empty?  # Ruby 1.9 apparently ignores the block if any argument is present
      initialize_without_optional_block(Yielder.new(&block))
    end
    Backports.alias_method_chain self, :initialize, :optional_block
  end

  Backports.alias_method self, :with_object, :each_with_object
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
backports-2.8.1 lib/backports/1.9.1/enumerator.rb
backports-2.8.0 lib/backports/1.9.1/enumerator.rb
backports-2.7.1 lib/backports/1.9.1/enumerator.rb
backports-2.7.0 lib/backports/1.9.1/enumerator.rb
backports-2.6.7 lib/backports/1.9.1/enumerator.rb
backports-2.6.6 lib/backports/1.9.1/enumerator.rb
backports-2.6.5 lib/backports/1.9.1/enumerator.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/backports-2.6.4/lib/backports/1.9.1/enumerator.rb
backports-2.6.4 lib/backports/1.9.1/enumerator.rb
backports-2.6.3 lib/backports/1.9.1/enumerator.rb
backports-2.6.2 lib/backports/1.9.1/enumerator.rb
backports-2.6.1 lib/backports/1.9.1/enumerator.rb
backports-2.6.0 lib/backports/1.9.1/enumerator.rb
backports-2.5.3 lib/backports/1.9.1/enumerator.rb
backports-2.5.2 lib/backports/1.9.1/enumerator.rb
backports-2.5.1 lib/backports/1.9.1/enumerator.rb
backports-2.5.0 lib/backports/1.9.1/enumerator.rb
backports-2.4.0 lib/backports/1.9.1/enumerator.rb
backports-2.3.0 lib/backports/1.9.1/enumerator.rb