Class: Multibases::DecodedByteArray

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

Instance Method Summary collapse

Methods inherited from ByteArray

#hash, #initialize, #is_a?, #to_arr, #transcode

Constructor Details

This class inherits a constructor from Multibases::ByteArray

Instance Method Details

#inspectObject



72
73
74
75
# File 'lib/multibases/byte_array.rb', line 72

def inspect
  encoding = @encoding || Encoding::BINARY
  "[Multibases::DecodedByteArray \"#{to_str(encoding)}\"]"
end

#to_ascii_strObject



83
84
85
# File 'lib/multibases/byte_array.rb', line 83

def to_ascii_str
  to_str(Encoding::US_ASCII)
end

#to_str(encoding = @encoding) ⇒ Object Also known as: to_s

Raises:



77
78
79
80
81
# File 'lib/multibases/byte_array.rb', line 77

def to_str(encoding = @encoding)
  raise MissingEncoding unless encoding

  pack('C*').force_encoding(encoding)
end

#to_utf8_strObject



87
88
89
# File 'lib/multibases/byte_array.rb', line 87

def to_utf8_str
  to_str(Encoding::UTF_8)
end