class RestrictedSet

Constants

VERSION

Public Class Methods

new(enum = nil, &block) click to toggle source
Calls superclass method
# File lib/restricted_set.rb, line 15
def initialize(enum = nil, &block)
  raise ArgumentError, "must provide a block" unless block_given?

  @proc = if block.arity == 2
            block.curry[self]
          else
            block
          end

  # Pass the identity proc to super to prevent
  # passing the given block argument through
  super(enum) { |o| o }
end

Public Instance Methods

<<(o)
Alias for: add
add(o) click to toggle source
# File lib/restricted_set.rb, line 29
def add(o)
  if @proc.call(o)
    @hash[o] = true
  end
  self
end
Also aliased as: <<
add?(o) click to toggle source
# File lib/restricted_set.rb, line 37
def add?(o)
  if include?(o) || !@proc.call(o)
    nil
  else
    @hash[o] = true
    self
  end
end
restriction_proc() click to toggle source
# File lib/restricted_set.rb, line 46
def restriction_proc
  @proc
end