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


49
50
51
52
# File 'lib/zold/id.rb', line 49

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)

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

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

#hashObject


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

def hash
  to_s.hash
end

#to_sObject


58
59
60
# File 'lib/zold/id.rb', line 58

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

#to_strObject


54
55
56
# File 'lib/zold/id.rb', line 54

def to_str
  to_s
end