Class: Array
- Defined in:
- lib/rdoba/a.rb,
lib/rdoba/dup.rb,
lib/rdoba/common.rb,
lib/rdoba/combinations.rb
Instance Method Summary collapse
- #>>(value = nil) ⇒ Object
- #[](index, *args) ⇒ Object
- #[]=(index, value, *args) ⇒ Object
- #__dup__ ⇒ Object
- #__get__ ⇒ Object
- #__set__ ⇒ Object
- #dup(opts = {}) ⇒ Object
- #each_comby(*args) ⇒ Object
-
#geta(index, options = {}) ⇒ Object
TODO => [] + class Index.
- #purge ⇒ Object
- #up0(v) ⇒ Object
- #up1(v) ⇒ Object
Instance Method Details
#>>(value = nil) ⇒ Object
77 78 79 |
# File 'lib/rdoba/common.rb', line 77 def >>(value = nil) value ? delete(value) : shift end |
#[](index, *args) ⇒ Object
82 83 84 85 |
# 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 |
#[]=(index, value, *args) ⇒ Object
88 89 90 91 |
# 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 |
#__dup__ ⇒ Object
5 |
# File 'lib/rdoba/dup.rb', line 5 alias :__dup__ :dup |
#__get__ ⇒ Object
81 |
# File 'lib/rdoba/common.rb', line 81 alias :__get__ :[] |
#__set__ ⇒ Object
87 |
# File 'lib/rdoba/common.rb', line 87 alias :__set__ :[]= |
#dup(opts = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# 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 |
#each_comby(*args) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# 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 = {}) ⇒ Object
TODO => [] + class Index
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rdoba/a.rb', line 7 def geta(index, = {}) #TODO => [] + class Index dbp11 "[geta] <<< array = #{self.inspect}, index = #{index.inspect}, options = #{.inspect}" [:сокр] ||= @сокр 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, ) : value else geta_value(index, ) end end |
#purge ⇒ Object
73 74 75 |
# File 'lib/rdoba/common.rb', line 73 def purge self.compact.delete_if {|x| x.empty? } end |
#up0(v) ⇒ Object
18 19 20 21 22 |
# 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) ⇒ Object
11 12 13 14 15 16 |
# 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 |