Module: ArrayUtils

Defined in:
lib/buzzcorej/extend_base_classes.rb

Instance Method Summary collapse

Instance Method Details

#filter_exclude(aValues, aArray = nil) ⇒ Object



365
366
367
368
# File 'lib/buzzcorej/extend_base_classes.rb', line 365

def filter_exclude(aValues,aArray=nil)
  aArray ||= self
  filter_exclude!(aValues,aArray.clone)
end

#filter_exclude!(aValues, aArray = nil) ⇒ Object



353
354
355
356
357
358
359
360
361
362
363
# File 'lib/buzzcorej/extend_base_classes.rb', line 353

def filter_exclude!(aValues,aArray=nil)
  aArray ||= self
  if aValues.is_a? Array
    return aArray if aValues.empty?
    return aArray.delete_if {|v| aValues.include? v }
  elsif aValues.is_a? Regexp
    return aArray.delete_if {|v| v =~ aValues }
  else
    return filter_exclude!([aValues],aArray)
  end
end

#filter_include(aValues, aArray = nil) ⇒ Object



348
349
350
351
# File 'lib/buzzcorej/extend_base_classes.rb', line 348

def filter_include(aValues,aArray=nil)
  aArray ||= self
  filter_include!(aValues,aArray.clone)
end

#filter_include!(aValues, aArray = nil) ⇒ Object



336
337
338
339
340
341
342
343
344
345
346
# File 'lib/buzzcorej/extend_base_classes.rb', line 336

def filter_include!(aValues,aArray=nil)
  aArray ||= self
  if aValues.is_a? Array
    return aArray if aValues.empty?
    return aArray.delete_if {|v| not aValues.include? v }
  elsif aValues.is_a? Regexp
    return aArray.delete_if {|v| not v =~ aValues }
  else
    return filter_include!([aValues],aArray)
  end
end

#to_nilObject



370
371
372
# File 'lib/buzzcorej/extend_base_classes.rb', line 370

def to_nil
	self.empty? ? nil : self
end