Class: Multibases::ByteArray

Inherits:
Array
  • Object
show all
Defined in:
lib/multibases/byte_array.rb

Direct Known Subclasses

DecodedByteArray, EncodedByteArray

Instance Method Summary collapse

Constructor Details

#initialize(array, encoding: nil) ⇒ ByteArray

Returns a new instance of ByteArray.



8
9
10
11
12
# File 'lib/multibases/byte_array.rb', line 8

def initialize(array, encoding: nil)
  super array

  @encoding = encoding
end

Instance Method Details

#hashObject



14
15
16
# File 'lib/multibases/byte_array.rb', line 14

def hash
  __getobj__.hash
end

#is_a?(klazz) ⇒ Boolean Also known as: kind_of?

Returns:

  • (Boolean)


22
23
24
# File 'lib/multibases/byte_array.rb', line 22

def is_a?(klazz)
  super || __getobj__.is_a?(klazz)
end

#to_arrObject Also known as: to_a



18
19
20
# File 'lib/multibases/byte_array.rb', line 18

def to_arr
  __getobj__.dup
end

#transcode(from, to, encoding: nil) ⇒ Object



26
27
28
29
30
31
# File 'lib/multibases/byte_array.rb', line 26

def transcode(from, to, encoding: nil)
  from = from.each_with_index.to_h
  to = Hash[to.each_with_index.to_a.collect(&:reverse)]

  self.class.new(map { |byte| to[from[byte]] }, encoding: encoding)
end