Sha256: 42842863f30129c5a4a88ca83cb650f6363766c92a80e399d9c114c6c29da7a1

Contents?: true

Size: 1.2 KB

Versions: 11

Compression:

Stored size: 1.2 KB

Contents

module Enumerable
  def only_kinds_of? *kinds    
    all?{|a| a.any_kind_of? *kinds }    
  end

  def only_labels?
    all?{|a| a.kind_of_label? }    
  end
  
  def select_kinds_of *kinds
    select{|a| a.any_kind_of? *kinds }
  end

  def select_kinds_of! *kinds
    select!{|a| a.any_kind_of? *kinds }
    self
  end

  def select_labels
    select{|a| a.kind_of_label? }
  end

  def select_labels!
    select!{|a| a.kind_of_label? }
    self
  end


  def select_symbols
    select_only :symbol
  end

  def select_symbols!
    select_only! :symbol
    self
  end

  def select_uniq_symbols!
    select_only!(:symbol).uniq!
    self
  end

  def select_strings
    select_only :string
  end

  def select_strings!
    select_only! :string
    self
  end

  def select_only type    
    const = type.kind_of_label? ? "#{type.to_s.camelize}".constantize : type
    select{|a| a.kind_of? const}
  end

  def select_only! type    
    const = type.kind_of_label? ? "#{type.to_s.camelize}".constantize : type
    select!{|a| a.kind_of? const}
    self
  end
  
  def all_kinds
    map do |a| 
      case a
      when Kinds
        a.kinds
      else
        a if a.kind_of?(Module)
      end
    end.compact.uniq.flatten
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sugar-high-0.4.7 lib/sugar-high/enumerable.rb
sugar-high-0.4.6.4 lib/sugar-high/enumerable.rb
sugar-high-0.4.6.3 lib/sugar-high/enumerable.rb
sugar-high-0.4.6.2 lib/sugar-high/enumerable.rb
sugar-high-0.4.6.1 lib/sugar-high/enumerable.rb
sugar-high-0.4.6 lib/sugar-high/enumerable.rb
sugar-high-0.4.5.2 lib/sugar-high/enumerable.rb
sugar-high-0.4.5 lib/sugar-high/enumerable.rb
sugar-high-0.4.4.2 lib/sugar-high/enumerable.rb
sugar-high-0.4.4.1 lib/sugar-high/enumerable.rb
sugar-high-0.4.4 lib/sugar-high/enumerable.rb