ruby self.send如何理解

时间:2015-10-20 07:41:58

标签: ruby

  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)

感谢

1 个答案:

答案 0 :(得分:3)

看起来像一种奇特的做法:

self.term == other.term and
self.index == other.index and
self.comment == other.comment