lib/sugar-high/array.rb in sugar-high-0.4.3 vs lib/sugar-high/array.rb in sugar-high-0.4.4
- old
+ new
@@ -2,39 +2,46 @@
require 'sugar-high/enumerable'
require 'sugar-high/path'
class Array
def to_symbols
- self.flatten.select_labels.map{|a| a.to_s.to_sym }
+ res = self.flatten.select_labels
+ res = res.map{|a| a.to_s.to_sym } if res
+ res || []
end
def to_symbols!
- self.flatten!.select_labels!.map!{|a| a.to_s.to_sym }
+ self.flatten!
+ self.select_labels!
+ self.map!{|a| a.to_s.to_sym }
+ self
end
def to_symbols_num
self.flatten.map{|a| a.kind_of?(Fixnum) ? "_#{a}" : a}.map{|a| a.to_s.to_sym }
end
def to_symbols_num!
- self.flatten!.map!{|a| a.kind_of?(Fixnum) ? "_#{a}" : a}..map!{|a| a.to_s.to_sym }
+ self.flatten!
+ self.map!{|a| a.kind_of?(Fixnum) ? "_#{a}" : a}.map!{|a| a.to_s.to_sym }
end
def to_symbols_uniq
to_symbols.uniq
end
def to_symbols_uniq!
- to_symbols!.uniq!
+ self.to_symbols!.uniq!
end
- def to_strings
- self.flatten!.select_labels!.map!(&:to_s)
+ def to_strings!
+ self.flatten!
+ self.select_labels!.map!(&:to_s)
end
- def to_strings!
- self.flatten.select_labels!.map!(&:to_s)
+ def to_strings
+ self.flatten.select_labels.map(&:to_s)
end
def to_filenames
self.to_strings.map(&:underscore)
end
@@ -47,10 +54,11 @@
self.map(&:path)
end
def to_paths!
self.map!(&:path)
+ self
end
def file_join
File.join(*self.flatten)
end
@@ -72,10 +80,13 @@
def flat_uniq
self.flatten.compact.uniq
end
def flat_uniq!
- self.flatten!.compact!.uniq!
+ self.flatten!
+ self.compact!
+ self.uniq!
+ self
end
def extract(sym)
map { |e| e.send(sym) }
end