-1
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"
在这一行?ruby self.send如何理解
self.send(attr) == other.send(attr)
感谢
你看过红宝石DOC(http://ruby-doc.org/core-2.2.3/ Object.html#方法-I-发送) –
重复:http://stackoverflow.com/q/3337285/2988 –