Sha256: 41ac2cb3424f57d2f41ec1971e163814d374f6c7015324efa5c0067fe0417302

Contents?: true

Size: 1.28 KB

Versions: 18

Compression:

Stored size: 1.28 KB

Contents

module Regin
  class Collection
    include Enumerable

    def initialize(*args)
      @array = Array.new(*args)
    end

    def each
      @array.each{ |item| yield item }
    end

    def [](i)
      @array[i]
    end

    def length
      @array.length
    end
    alias_method :size, :length

    def first
      @array.first
    end

    def last
      @array.last
    end

    def +(other)
      ary = other.is_a?(self.class) ? other.internal_array : other
      self.class.new(@array + ary)
    end

    def to_regexp(anchored = false)
      re = to_s(true)
      re = "\\A#{re}\\Z" if anchored
      Regexp.compile(re, flags)
    end

    def match(char)
      to_regexp.match(char)
    end

    def include?(char)
      any? { |e| e.include?(char) }
    end

    def ==(other) #:nodoc:
      case other
      when String
        other == to_s
      when Array
        other == @array
      else
        eql?(other)
      end
    end

    def eql?(other) #:nodoc:
      other.instance_of?(self.class) && @array.eql?(other.internal_array)
    end

    protected
      def internal_array #:nodoc:
        @array
      end

      def extract_options(args)
        if args.last.is_a?(Hash)
          return args[0..-2], args.last
        else
          return args, {}
        end
      end
  end
end

Version data entries

18 entries across 18 versions & 3 rubygems

Version Path
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/rack-mount-0.8.3/lib/rack/mount/vendor/regin/regin/collection.rb
rack-mount-0.8.3 lib/rack/mount/vendor/regin/regin/collection.rb
rack-mount-0.8.2 lib/rack/mount/vendor/regin/regin/collection.rb
rack-mount-0.8.1 lib/rack/mount/vendor/regin/regin/collection.rb
rack-mount-0.8.0 lib/rack/mount/vendor/regin/regin/collection.rb
rack-mount-0.7.4 lib/rack/mount/vendor/regin/regin/collection.rb
rack-mount-0.7.3 lib/rack/mount/vendor/regin/regin/collection.rb
rack-mount-0.7.2 lib/rack/mount/vendor/regin/regin/collection.rb
rack-mount-0.7.1 lib/rack/mount/vendor/regin/regin/collection.rb
rack-mount-0.6.14 lib/rack/mount/vendor/regin/regin/collection.rb
lgierth-rack-mount-0.6.13 lib/rack/mount/vendor/regin/regin/collection.rb
rack-mount-0.6.13 lib/rack/mount/vendor/regin/regin/collection.rb
rack-mount-0.6.12 lib/rack/mount/vendor/regin/regin/collection.rb
rack-mount-0.6.11 lib/rack/mount/vendor/regin/regin/collection.rb
rack-mount-0.6.10 lib/rack/mount/vendor/regin/regin/collection.rb
rack-mount-0.6.9 lib/rack/mount/vendor/regin/regin/collection.rb
rack-mount-0.6.8 lib/rack/mount/vendor/regin/regin/collection.rb
rack-mount-0.6.7 lib/rack/mount/vendor/regin/regin/collection.rb