Class: Raft::LogEntry

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(term, index, command) ⇒ LogEntry

Returns a new instance of LogEntry.



21
22
23
# File 'lib/raft.rb', line 21

def initialize(term, index, command)
  @term, @index, @command = term, index, command
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



19
20
21
# File 'lib/raft.rb', line 19

def command
  @command
end

#indexObject (readonly)

Returns the value of attribute index.



19
20
21
# File 'lib/raft.rb', line 19

def index
  @index
end

#termObject (readonly)

Returns the value of attribute term.



19
20
21
# File 'lib/raft.rb', line 19

def term
  @term
end

Instance Method Details

#==(other) ⇒ Object



25
26
27
28
29
# File 'lib/raft.rb', line 25

def ==(other)
  [:term, :index, :command].all? do |attr|
    self.send(attr) == other.send(attr)
  end
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/raft.rb', line 31

def eql?(other)
  self == other
end

#hashObject



35
36
37
38
39
# File 'lib/raft.rb', line 35

def hash
  [:term, :index, :command].reduce(0) do |h, attr|
    h ^= self.send(attr)
  end
end