class LogEntry
attr_reader :term, :index, :command
def initialize(term, index, command)
@term, @index, @command = term, index, command
end
def ==(other)
[:term, :index, :command].all? do |attr|
self.send(attr) == other.send(attr)
end
end
def eql?(other)
self == other
end
def hash
[:term, :index, :command].reduce(0) do |h, attr|
h ^= self.send(attr)
end
end
end
我正在阅读这样的代码,如何在这一行理解"self.send"
?
self.send(attr) == other.send(attr)
感谢
答案 0 :(得分:3)
看起来像一种奇特的做法:
self.term == other.term and
self.index == other.index and
self.comment == other.comment