module RorHack::ArrayHack
Public Instance Methods
all_blank?()
click to toggle source
# File lib/ror_hack/array_hack.rb, line 30 def all_blank? self.all?(&:blank?) end
all_present?()
click to toggle source
# File lib/ror_hack/array_hack.rb, line 38 def all_present? self.all?(&:present?) end
any_blank?()
click to toggle source
# File lib/ror_hack/array_hack.rb, line 34 def any_blank? self.any?(&:blank?) end
any_present?()
click to toggle source
# File lib/ror_hack/array_hack.rb, line 42 def any_present? self.any?(&:present?) end
include_all?(*args)
click to toggle source
# File lib/ror_hack/array_hack.rb, line 26 def include_all?(*args) args.all? { |i| i.in? self } end
include_any?(*args)
click to toggle source
# File lib/ror_hack/array_hack.rb, line 22 def include_any?(*args) args.any? { |i| i.in? self } end
left_push(num, ele = nil)
click to toggle source
# File lib/ror_hack/array_hack.rb, line 70 def left_push(num, ele = nil) unshift(ele) while size < num self end
left_strip_nil()
click to toggle source
清空左边为nil的所有元素.
# File lib/ror_hack/array_hack.rb, line 53 def left_strip_nil while first.nil? delete_at(0) break if size == 0 end self end
multi_group_by(*keys)
click to toggle source
# File lib/ror_hack/array_hack.rb, line 3 def multi_group_by(*keys) group_by_block = lambda do |array, ks| key = ks.shift return array unless key if key.is_a? Proc hash = array.group_by(&key) else hash = array.group_by { |i| i[key] } end if ks.present? hash.keys.each do |k| hash[k] = group_by_block.call hash[k], ks.dup end end return hash end group_by_block.call self, keys end
right_push(num, ele = nil)
click to toggle source
# File lib/ror_hack/array_hack.rb, line 65 def right_push(num, ele = nil) push(ele) while size < num self end
right_strip_nil()
click to toggle source
# File lib/ror_hack/array_hack.rb, line 46 def right_strip_nil self.reverse! left_strip_nil reverse end
strip_nil()
click to toggle source
# File lib/ror_hack/array_hack.rb, line 61 def strip_nil left_strip_nil.right_strip_nil end