Class: Zold::Id
- Inherits:
-
Object
- Object
- Zold::Id
- 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
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(id = nil) ⇒ Id
constructor
A new instance of Id.
- #to_s ⇒ Object
- #to_str ⇒ Object
Constructor Details
#initialize(id = nil) ⇒ Id
Returns a new instance of Id.
30 31 32 33 34 35 36 37 |
# File 'lib/zold/id.rb', line 30 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
56 57 58 59 |
# File 'lib/zold/id.rb', line 56 def <=>(other) raise 'Can only compare with Id' unless other.is_a?(Id) to_s <=> other.to_s end |
#==(other) ⇒ Object
51 52 53 54 |
# File 'lib/zold/id.rb', line 51 def ==(other) raise 'Can only compare with Id' unless other.is_a?(Id) to_s == other.to_s end |
#eql?(other) ⇒ Boolean
42 43 44 45 |
# File 'lib/zold/id.rb', line 42 def eql?(other) raise 'Can only compare with Id' unless other.is_a?(Id) to_s == other.to_s end |
#hash ⇒ Object
47 48 49 |
# File 'lib/zold/id.rb', line 47 def hash to_s.hash end |
#to_s ⇒ Object
65 66 67 |
# File 'lib/zold/id.rb', line 65 def to_s format('%016x', @id) end |
#to_str ⇒ Object
61 62 63 |
# File 'lib/zold/id.rb', line 61 def to_str to_s end |