Module: Enumerable
- Defined in:
- lib/sugar-high/enumerable.rb
Instance Method Summary collapse
- #all_kinds ⇒ Object
- #only_kinds_of?(*kinds) ⇒ Boolean
- #only_labels? ⇒ Boolean
- #only_numbers? ⇒ Boolean
- #select_kinds_of(*kinds) ⇒ Object
- #select_kinds_of!(*kinds) ⇒ Object
- #select_labels ⇒ Object
- #select_labels! ⇒ Object
- #select_numbers ⇒ Object
- #select_numbers! ⇒ Object
- #select_only(type) ⇒ Object
- #select_only!(type) ⇒ Object
- #select_strings ⇒ Object
- #select_strings! ⇒ Object
- #select_symbols ⇒ Object
- #select_symbols! ⇒ Object
- #select_uniq_symbols! ⇒ Object
Instance Method Details
#all_kinds ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/sugar-high/enumerable.rb', line 75 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 |
#only_kinds_of?(*kinds) ⇒ Boolean
2 3 4 |
# File 'lib/sugar-high/enumerable.rb', line 2 def only_kinds_of? *kinds all?{|a| a.any_kind_of? *kinds } end |
#only_labels? ⇒ Boolean
6 7 8 |
# File 'lib/sugar-high/enumerable.rb', line 6 def only_labels? all?{|a| a.kind_of_label? } end |
#only_numbers? ⇒ Boolean
10 11 12 |
# File 'lib/sugar-high/enumerable.rb', line 10 def only_numbers? all?{|a| a.kind_of_number? } end |
#select_kinds_of(*kinds) ⇒ Object
14 15 16 |
# File 'lib/sugar-high/enumerable.rb', line 14 def select_kinds_of *kinds select{|a| a.any_kind_of? *kinds } end |
#select_kinds_of!(*kinds) ⇒ Object
18 19 20 21 |
# File 'lib/sugar-high/enumerable.rb', line 18 def select_kinds_of! *kinds select!{|a| a.any_kind_of? *kinds } self end |
#select_labels ⇒ Object
23 24 25 |
# File 'lib/sugar-high/enumerable.rb', line 23 def select_labels select{|a| a.kind_of_label? } end |
#select_labels! ⇒ Object
36 37 38 39 |
# File 'lib/sugar-high/enumerable.rb', line 36 def select_labels! select!{|a| a.kind_of_label? } self end |
#select_numbers ⇒ Object
27 28 29 |
# File 'lib/sugar-high/enumerable.rb', line 27 def select_numbers select{|a| a.is_a?(Numeric) } end |
#select_numbers! ⇒ Object
31 32 33 34 |
# File 'lib/sugar-high/enumerable.rb', line 31 def select_numbers! select!{|a| a.is_a?(Numeric) } self end |
#select_only(type) ⇒ Object
64 65 66 67 |
# File 'lib/sugar-high/enumerable.rb', line 64 def select_only type const = type.kind_of_label? ? "#{type.to_s.camelize}".constantize : type select{|a| a.kind_of? const} end |
#select_only!(type) ⇒ Object
69 70 71 72 73 |
# File 'lib/sugar-high/enumerable.rb', line 69 def select_only! type const = type.kind_of_label? ? "#{type.to_s.camelize}".constantize : type select!{|a| a.kind_of? const} self end |
#select_strings ⇒ Object
55 56 57 |
# File 'lib/sugar-high/enumerable.rb', line 55 def select_strings select_only :string end |
#select_strings! ⇒ Object
59 60 61 62 |
# File 'lib/sugar-high/enumerable.rb', line 59 def select_strings! select_only! :string self end |
#select_symbols ⇒ Object
41 42 43 |
# File 'lib/sugar-high/enumerable.rb', line 41 def select_symbols select_only :symbol end |
#select_symbols! ⇒ Object
45 46 47 48 |
# File 'lib/sugar-high/enumerable.rb', line 45 def select_symbols! select_only! :symbol self end |
#select_uniq_symbols! ⇒ Object
50 51 52 53 |
# File 'lib/sugar-high/enumerable.rb', line 50 def select_uniq_symbols! select_only!(:symbol).uniq! self end |