Sha256: 048a7195049ba18a1e6c4da470eb45cb328db5932a9e6f75f1f86faa90c4a8b9

Contents?: true

Size: 591 Bytes

Versions: 4

Compression:

Stored size: 591 Bytes

Contents

require 'forwardable'

module Hypercuke
  class NameList
    attr_reader :names
    private :names

    def initialize(*names)
      @names = names.flatten
    end

    def define(new_name)
      name = new_name.to_sym
      names << name unless names.include?(name)
    end

    def validate(name)
      if valid_name?(name)
        return name.to_sym
      else
        yield if block_given?
        return nil
      end
    end

    def valid_name?(name)
      names.include?(name.to_sym)
    end

    def to_a
      names.dup
    end

    def empty?
      names.empty?
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hypercuke-0.5.2 lib/hypercuke/name_list.rb
hypercuke-0.5.1 lib/hypercuke/name_list.rb
hypercuke-0.5.0 lib/hypercuke/name_list.rb
hypercuke-0.4.1 lib/hypercuke/name_list.rb