Class: Bio::RestrictionEnzyme::SortedNumArray
- Defined in:
- lib/bio/util/restriction_enzyme/sorted_num_array.rb
Overview
a class to store sorted numerics.
Bio::RestrictionEnzyme internal use only. Please do not create the instance outside Bio::RestrictionEnzyme.
Class Method Summary collapse
-
.[](*args) ⇒ Object
Same usage as Array.[].
Instance Method Summary collapse
-
#+(other) ⇒ Object
Same usage as Array#+, but accepts only the same classes instance.
-
#<<(elem) ⇒ Object
Same usage as Array#<<.
-
#==(other) ⇒ Object
Same usage as Array#==.
-
#[](*arg) ⇒ Object
Same usage as Array#[].
-
#[]=(*arg) ⇒ Object
Not implemented.
-
#concat(ary) ⇒ Object
Same usage as Array#concat.
-
#delete(elem) ⇒ Object
Same usage as Array#delete.
-
#each(&block) ⇒ Object
Same usage as Array#each.
-
#first ⇒ Object
Same usage as Array#first.
-
#include?(elem) ⇒ Boolean
Same usage as Array#include?.
-
#initialize ⇒ SortedNumArray
constructor
Creates a new object.
-
#initialize_copy(other) ⇒ Object
initialize copy.
-
#last ⇒ Object
Same usage as Array#last.
-
#push(*args) ⇒ Object
Same usage as Array#push.
-
#reverse_each(&block) ⇒ Object
Same usage as Array#reverse_each.
-
#size ⇒ Object
(also: #length)
Same usage as Array#size.
-
#sort!(&block) ⇒ Object
Does nothing.
-
#to_a ⇒ Object
Converts to an array.
-
#uniq! ⇒ Object
Does nothing.
-
#unshift(*arg) ⇒ Object
Same usage as Array#unshift.
Constructor Details
#initialize ⇒ SortedNumArray
Creates a new object
28 29 30 31 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 28 def initialize @hash = {} #clear_cache end |
Class Method Details
.[](*args) ⇒ Object
Same usage as Array.[]
19 20 21 22 23 24 25 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 19 def self.[](*args) a = self.new args.each do |elem| a.push elem end a end |
Instance Method Details
#+(other) ⇒ Object
Same usage as Array#+, but accepts only the same classes instance.
121 122 123 124 125 126 127 128 129 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 121 def +(other) unless other.is_a?(self.class) then raise TypeError, 'unsupported data type' end new_hash = @hash.merge(other.internal_data_hash) result = self.class.new result.internal_data_hash = new_hash result end |
#<<(elem) ⇒ Object
Same usage as Array#<<
165 166 167 168 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 165 def <<(elem) push_element(elem) self end |
#==(other) ⇒ Object
Same usage as Array#==
132 133 134 135 136 137 138 139 140 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 132 def ==(other) if r = super(other) then r elsif other.is_a?(self.class) then other.internal_data_hash == @hash else false end end |
#[](*arg) ⇒ Object
Same usage as Array#[]
100 101 102 103 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 100 def [](*arg) #$stderr.puts "SortedNumArray#[]" sorted_keys[*arg] end |
#[]=(*arg) ⇒ Object
Not implemented
106 107 108 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 106 def []=(*arg) raise NotImplementedError, 'SortedNumArray#[]= is not implemented.' end |
#concat(ary) ⇒ Object
Same usage as Array#concat
143 144 145 146 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 143 def concat(ary) ary.each { |elem| push_element(elem) } self end |
#delete(elem) ⇒ Object
Same usage as Array#delete
192 193 194 195 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 192 def delete(elem) #clear_cache @hash.delete(elem) ? elem : nil end |
#each(&block) ⇒ Object
Same usage as Array#each
111 112 113 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 111 def each(&block) sorted_keys.each(&block) end |
#first ⇒ Object
Same usage as Array#first
176 177 178 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 176 def first sorted_keys.first end |
#include?(elem) ⇒ Boolean
Same usage as Array#include?
171 172 173 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 171 def include?(elem) @hash.has_key?(elem) end |
#initialize_copy(other) ⇒ Object
initialize copy
34 35 36 37 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 34 def initialize_copy(other) super(other) @hash = @hash.dup end |
#last ⇒ Object
Same usage as Array#last
181 182 183 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 181 def last sorted_keys.last end |
#push(*args) ⇒ Object
Same usage as Array#push
149 150 151 152 153 154 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 149 def push(*args) args.each do |elem| push_element(elem) end self end |
#reverse_each(&block) ⇒ Object
Same usage as Array#reverse_each
116 117 118 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 116 def reverse_each(&block) sorted_keys.reverse_each(&block) end |
#size ⇒ Object Also known as: length
Same usage as Array#size
186 187 188 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 186 def size @hash.size end |
#sort!(&block) ⇒ Object
Does nothing
198 199 200 201 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 198 def sort!(&block) # does nothing self end |
#to_a ⇒ Object
Converts to an array
210 211 212 213 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 210 def to_a #sorted_keys.dup sorted_keys end |
#uniq! ⇒ Object
Does nothing
204 205 206 207 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 204 def uniq! # does nothing self end |
#unshift(*arg) ⇒ Object
Same usage as Array#unshift
157 158 159 160 161 162 |
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 157 def unshift(*arg) arg.reverse_each do |elem| unshift_element(elem) end self end |