Sha256: 9e505b17e02ec6f6439d21247e7468df4dffb323a250663ac4b1070baaf2ad14

Contents?: true

Size: 513 Bytes

Versions: 1

Compression:

Stored size: 513 Bytes

Contents

# frozen_string_literal: true

module NameQ
  module Support
    class List
      def initialize(items = nil, case_sensitive: true, &refill)
        @items = items || []
        @comparator = case_sensitive ? :eql? : :casecmp?
        @refill = refill
      end

      def add(name)
        @items << name
        name
      end

      def include?(name)
        all.any? { |a| a.send(@comparator, name) }
      end

      private

      def all
        @items + (@refill&.call || [])
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nameq-0.0.3 lib/nameq/support/list.rb