class Array
coding:utf-8
Public Instance Methods
>>(value = nil)
click to toggle source
# File lib/rdoba/common.rb, line 77 def >>(value = nil) value ? delete(value) : shift end
[](index, *args)
click to toggle source
# File lib/rdoba/common.rb, line 82 def [](index, *args) return __get__(index.to_i, *args) if index.class == String and index =~ /^\d+$/ __get__(index, *args) end
Also aliased as: __get__
[]=(index, value, *args)
click to toggle source
# File lib/rdoba/common.rb, line 88 def []=(index, value, *args) return __set__(index.to_i, value, *args) if index.class == String and index =~ /^\d+$/ __set__(index, value, *args) end
Also aliased as: __set__
dup(opts = {})
click to toggle source
# File lib/rdoba/dup.rb, line 6 def dup(opts = {}) if (opts.class == Hash ? opts.key?(:recursive) : opts.to_s.to_sym == :recursive) res = [] def sub_dup(value) if value.class.to_s =~ /(Hash|Array)/ value.dup(:recursive) else begin value.dup rescue new = value end end end self.each do |value| res << sub_dup(value) end res elsif opts.empty? __dup__ else raise "Unsupported option(s): #{opts.class == Hash ? opts.keys.join(', ') : opts}" end end
Also aliased as: __dup__
each_comby(*args) { |dup| ... }
click to toggle source
# File lib/rdoba/combinations.rb, line 40 def each_comby(*args) return self if self.empty? or not block_given? if args.include?(:backward) yield [ self.dup ] ((1 << (self.size - 1)) - 2).downto(0) do |i| c = __comby(i, self.size - 1) yield c end else 0.upto((1 << (self.size - 1)) - 2) do |i| c = __comby(i, self.size - 1) yield c end yield [ self.dup ] end return self end
geta(index, options = {})
click to toggle source
# File lib/rdoba/a.rb, line 7 def geta(index, options = {}) #TODO => [] + class Index dbp11 "[geta] <<< array = #{self.inspect}, index = #{index.inspect}, options = #{options.inspect}" options[:сокр] ||= @сокр if index.class == Array return self if index == [] or index == [''] index = index.clone value = self[index.shift] (value.class == Hash or value.class == Array) ? value.geta(index, options) : value else geta_value(index, options) end end
purge()
click to toggle source
# File lib/rdoba/common.rb, line 73 def purge self.compact.delete_if {|x| x.empty? } end
sub_dup(value)
click to toggle source
# File lib/rdoba/dup.rb, line 10 def sub_dup(value) if value.class.to_s =~ /(Hash|Array)/ value.dup(:recursive) else begin value.dup rescue new = value end end end
Private Instance Methods
__comby(i, size)
click to toggle source
# File lib/rdoba/combinations.rb, line 7 def __comby(i, size) s = "0#{sprintf("%.*b", size, i)}0" v = { :res => [], :c0 => 0, :c1 => 0, :j => 0} def up1(v) sub_j = v[:j] + v[:c1] + 1 v[:res] << self[v[:j]...sub_j] v[:j] = sub_j v[:c1] = 0 end def up0(v) sub_j = v[:j] + v[:c0] - 1 self[v[:j]...sub_j].each do |x| v[:res] << [x] end v[:j] = sub_j end s.each_char do |c| if c == '1' v[:c1] += 1 up0(v) if v[:c0] > 1 v[:c0] = 0 else v[:c0] += 1 up1(v) if v[:c1] > 0 end end up0(v) if v[:c0] > 1 v[:res] end
up0(v)
click to toggle source
# File lib/rdoba/combinations.rb, line 18 def up0(v) sub_j = v[:j] + v[:c0] - 1 self[v[:j]...sub_j].each do |x| v[:res] << [x] end v[:j] = sub_j end
up1(v)
click to toggle source
# File lib/rdoba/combinations.rb, line 11 def up1(v) sub_j = v[:j] + v[:c1] + 1 v[:res] << self[v[:j]...sub_j] v[:j] = sub_j v[:c1] = 0 end