module ExtendIt::ArrayOf::ArrayMethods

Public Class Methods

new(*arr) click to toggle source
Calls superclass method
# File lib/extend_it/array_of.rb, line 63
def initialize(*arr)
  @array = self.class.select(arr.flatten)
  super(@array)
end

Public Instance Methods

<<(obj) click to toggle source
# File lib/extend_it/array_of.rb, line 104
def <<(obj)
  return unless self.class.entity?(obj)
  @array << obj
end
[](*args) click to toggle source
# File lib/extend_it/array_of.rb, line 77
def [](*args)
  if args.size == 1 && args.first.is_a?(Symbol)
    unless self.class.finder.nil?
      return @array.find { |e| self.class.finder.call(e) == args.first }
    end
  else
  end
  @array[*args]
end
[]=(*args) click to toggle source
# File lib/extend_it/array_of.rb, line 109
def []=(*args)
  return unless self.class.entity?(args.last)
  @array.send(:[]=, *args)
end
fill(*args) { |index| ... } click to toggle source
# File lib/extend_it/array_of.rb, line 129
def fill(*args)
  if block_given?
    @array.fill(*args) do |index|
      obj = yield index
      self.class.entity?(obj) ? obj : @array[index]
    end
  else
    return self unless self.class.entity?(args.first)
    @array.fill(*args)
  end
  self
end
insert(index, *other) click to toggle source
# File lib/extend_it/array_of.rb, line 142
def insert(index, *other)
  @array.insert(index, self.class.select(other))
  self
end
map!(&block) click to toggle source
# File lib/extend_it/array_of.rb, line 147
def map!(&block)
  array = @array
  array_class = self.class
  enum = Enumerator.new do |yielder|
    array.replace(array.map do |entity|
      obj = (yielder << entity)
      array_class.entity?(obj) ? obj : nil
    end.compact)
  end
  if block_given?
    enum.each(&block)
    self
  else
    enum
  end
end
scope(name) click to toggle source
# File lib/extend_it/array_of.rb, line 68
def scope(name)
  if name.is_a?(Symbol)
    if self.class.scopes.include?(name)
      self.class.new(@array.select(&self.class.scopes[name]))
    end
  else
  end
end
to_a() click to toggle source
# File lib/extend_it/array_of.rb, line 114
def to_a
  @array
end
to_ary() click to toggle source
# File lib/extend_it/array_of.rb, line 118
def to_ary
  @array
end