-2
  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

I am reading a code like this, how to understand "self.send" at this line?

self.send(attr) == other.send(attr)

thanks

BufBills
  • 8,005
  • 12
  • 48
  • 90

1 Answers1

3

Looks like a fancy way of doing:

self.term == other.term and
self.index == other.index and
self.comment == other.comment
Mattias Wadman
  • 11,172
  • 2
  • 42
  • 57