Parent

Files

Array

Public Instance Methods

args() click to toggle source
# File lib/sugar-high/arguments.rb, line 2
def args
  flatten.map{|a| a.args}.flatten
end
extract(sym) click to toggle source
# File lib/sugar-high/array.rb, line 106
def extract(sym)
 map { |e| e.send(sym) }
end
extract_options!() click to toggle source

Repeat overall-used method here, to use it without Rails

# File lib/sugar-high/array.rb, line 111
def extract_options!
  last.is_a?(::Hash) ? pop : {}
end
file_join() click to toggle source
# File lib/sugar-high/array.rb, line 77
def file_join
  File.join(*self.flatten)
end
file_names(ext = '*') click to toggle source
# File lib/sugar-high/file.rb, line 34
def file_names ext = '*'
  self.map{|a| a.gsub( /(.*)\//, '').gsub(/\.#{Regexp.escape(ext.to_s)}/, '')}
end
flat_uniq() click to toggle source
# File lib/sugar-high/array.rb, line 95
def flat_uniq
 self.flatten.compact.uniq
end
flat_uniq!() click to toggle source
# File lib/sugar-high/array.rb, line 99
def flat_uniq!
 self.flatten!
 self.compact!
 self.uniq!
 self
end
grep_it(expr) click to toggle source
# File lib/sugar-high/regexp.rb, line 24
def grep_it expr
  return self if !expr
  self.grep(expr.to_regexp)
end
last_arg(default = {}) click to toggle source
# File lib/sugar-high/arguments.rb, line 12
def last_arg default = {}
  last = self.flatten.last
  last.kind_of?(Hash) ? last : default
end
last_arg_value(default = nil) click to toggle source
# File lib/sugar-high/arguments.rb, line 17
def last_arg_value default = nil
  last = self.flatten.last
  raise ArgumentError, "Default value must be a Hash, was #{default}" if !default.kind_of? Hash
  key = default.keys.first
  return default[key] if !last.kind_of? Hash
  last[key] ? last[key] : default[key]
end
last_option() click to toggle source
# File lib/sugar-high/arguments.rb, line 6
def last_option
  default = self.last_arg
  last = self.flatten.last
  last.kind_of?(Hash) ? last : default
end
none?() click to toggle source
# File lib/sugar-high/array.rb, line 91
def none?
  self.flatten.compact.empty?
end
pick(num) click to toggle source
# File lib/sugar-high/array.rb, line 11
def pick num
  num.times.inject([]) {|res, x| res << pick_one!}
end
pick_one!() click to toggle source
# File lib/sugar-high/array.rb, line 6
def pick_one!
  index = Kernel.rand(self.size)
  self[index]
end
select!(&block) click to toggle source
# File lib/sugar-high/array.rb, line 115
def select! &block
  replace select &block
end
to_filenames() click to toggle source
# File lib/sugar-high/array.rb, line 60
def to_filenames
  self.to_strings.map(&:underscore)
end
to_filenames!() click to toggle source
# File lib/sugar-high/array.rb, line 64
def to_filenames!
  self.to_strings!.map!(&:underscore)
end
to_files() click to toggle source
# File lib/sugar-high/array.rb, line 81
def to_files
  self.map{|fp| fp.path.to_file }
  self.extend FilesArray
end
to_files!() click to toggle source
# File lib/sugar-high/array.rb, line 86
def to_files!
  self.map!{|fp| fp.path.to_file }
  self.extend FilesArray
end
to_paths() click to toggle source
# File lib/sugar-high/array.rb, line 68
def to_paths
  self.map(&:path)
end
to_paths!() click to toggle source
# File lib/sugar-high/array.rb, line 72
def to_paths!
  self.map!(&:path)
  self
end
to_strings() click to toggle source
# File lib/sugar-high/array.rb, line 56
def to_strings
  self.flatten.select_labels.map(&:to_s)
end
to_strings!() click to toggle source
# File lib/sugar-high/array.rb, line 51
def to_strings!
  self.flatten!
  self.select_labels!.map!(&:to_s)
end
to_symbols() click to toggle source
# File lib/sugar-high/array.rb, line 21
def to_symbols
  res = self.flatten.select_labels
  res = res.map{|a| a.to_s.to_sym } if res
  res || []
end
to_symbols!() click to toggle source
# File lib/sugar-high/array.rb, line 27
def to_symbols!
 self.flatten!
 self.select_labels!
 self.map!{|a| a.to_s.to_sym }
 self
end
to_symbols_num() click to toggle source
# File lib/sugar-high/array.rb, line 34
def to_symbols_num
  self.flatten.map{|a| a.kind_of?(Fixnum) ? "_#{a}" : a}.map{|a| a.to_s.to_sym }
end
to_symbols_num!() click to toggle source
# File lib/sugar-high/array.rb, line 38
def to_symbols_num!
  self.flatten!
  self.map!{|a| a.kind_of?(Fixnum) ? "_#{a}" : a}.map!{|a| a.to_s.to_sym }
end
to_symbols_uniq() click to toggle source
# File lib/sugar-high/array.rb, line 43
def to_symbols_uniq
  to_symbols.uniq
end
to_symbols_uniq!() click to toggle source
# File lib/sugar-high/array.rb, line 47
def to_symbols_uniq!
  self.to_symbols!.uniq!
end
without(*values) click to toggle source
# File lib/sugar-high/array.rb, line 15
def without(*values)
   copy = self.dup
   values.flatten.each { |value| copy.delete(value) }
   copy
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.