lib/sugar-high/kind_of.rb in sugar-high-0.2.0 vs lib/sugar-high/kind_of.rb in sugar-high-0.2.1

- old
+ new

@@ -1,5 +1,7 @@ +require "active_support/inflector" + class Object def any_kind_of? *kinds kinds.all_kinds.each do |kind| return true if self.kind_of? kind end @@ -24,9 +26,26 @@ all?{|a| a.kind_of_label? } end def select_kinds_of *kinds select{|a| a.any_kind_of? *kinds } + end + + def select_labels + select{|a| a.kind_of_label? } + end + + def select_symbols + select{|a| a.kind_of_symbol? } + end + + def select_strings + select_only :string + end + + def select_only type + const = type.kind_of_label? ? "#{type.to_s.camelize}".constantize : type + select{|a| a.kind_of? const} end def all_kinds map do |a| case a \ No newline at end of file