Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Things like "super.tap" make me think I'm about to go on a wild goose chase.


It's pretty simple and useful; instead of

  def my_method
    super_result = super
    ...
    (do something with super_result, or simply after super has been called)
    ...
    super_result <== to make sure your method returns the result of super
  end
you can just do this:

  def my_method
    super.tap{|result| (do something with/after result) } <== will still return the result of super
  end


I know what it does, but isn't it (and your examples) an instance of the Call Super[1] antipattern?

1. https://www.martinfowler.com/bliki/CallSuper.html


From my understanding, the anti-pattern is related to creating an API that requires a call to super when overriding a method. super.tap may be used when interacting with an API that employs the "call super" anti-pattern, but calling super is not itself an instance of the anti-pattern; it can be used in perfectly legitimate cases as well.


Tap is by far my favorite method though usually on hashes to add conditionals




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: