shlogg · Early preview
Augusts Bautra @augustsbautra

Rubocop's Lint/Void Rule: A Surprising Exception

Ruby's Lint/Void rule has an exception: when called via `super`, last expression is returned, not value passed. This can lead to unexpected behavior.

Today I was working on autofixing rubocop offences and Lint/Void gave me a nasty surprise. Supposedly in Ruby the return value of assignment methods like def field=(value) will be special in that it's always the value passed, irrespective of what the last expression in the method body was. While true, this rule has an unusual exception - being called via super. In that case the last expression is returned, confusoring everyone.
Try this code and see:

class Parent
  def value=(v)
    @value = v
    :p # should never be returned, but using super in an inheriting class does get to it.
  end
  de...