Module: Scale::Types::FixedWidthUInt

Includes:
Base
Included in:
U128, U16, U256, U32, U512, U64, U8
Defined in:
lib/scale/base.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary

Attributes included from Base

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#==, #initialize, #to_human

Class Method Details

.included(base) ⇒ Object



144
145
146
# File 'lib/scale/base.rb', line 144

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#encodeObject



148
149
150
151
152
153
154
155
# File 'lib/scale/base.rb', line 148

def encode
  if value.class != ::Integer
    raise "#{self.class}'s value must be integer"
  end
  byte_length = self.class::BYTE_LENGTH
  bytes = value.to_s(16).rjust(byte_length * 2, "0").scan(/.{2}/).reverse.map {|hex| hex.to_i(16) }
  bytes.bytes_to_hex[2..]
end