Skip to content

Files

Latest commit

 

History

History
38 lines (28 loc) · 1 KB

Style-RedundantSelf.md

File metadata and controls

38 lines (28 loc) · 1 KB

Pattern: Redundant self

Issue: -

Description

This rule checks for redundant uses of self.

self is only needed when sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

Examples

# bad
def ready?
  if self.last_reviewed_at > self.last_updated_at
    self.worker.update(self.content, self.options)
    self.status = :in_progress
  end
  self.status == :verified
end

# good
def ready?
  if last_reviewed_at > last_updated_at
    worker.update(content, options)
    self.status = :in_progress
  end
  status == :verified
end

Further Reading