Class: Zold::Id

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/id.rb

Overview

Id of the wallet

Constant Summary collapse

ROOT =

The ID of the root wallet.

Id.new('0000000000000000')

Instance Method Summary collapse

Constructor Details

#initialize(id = nil) ⇒ Id

Returns a new instance of Id.



28
29
30
31
32
33
34
35
# File 'lib/zold/id.rb', line 28

def initialize(id = nil)
  if id.nil?
    @id = rand(2**32..2**64 - 1)
  else
    raise "Invalid wallet ID '#{id}'" unless id =~ /^[0-9a-fA-F]{16}$/
    @id = Integer("0x#{id}", 16)
  end
end

Instance Method Details

#==(other) ⇒ Object



40
41
42
43
# File 'lib/zold/id.rb', line 40

def==(other)
  raise 'Can only compare with Id' unless other.is_a?(Id)
  to_s == other.to_s
end

#to_sObject



45
46
47
# File 'lib/zold/id.rb', line 45

def to_s
  format('%016x', @id)
end