Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Monkey patching in Ruby

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.
Avatar for Cam Huynh Cam Huynh
November 24, 2015

Monkey patching in Ruby

My presentation at hcmc.rb meetup (hosted by Ruby Vietnam) on 25 Nov 2015

- What's monkey patching?
- The pros and cons of monkey patching.
- How to monkey-patch without making a mess.

Avatar for Cam Huynh

Cam Huynh

November 24, 2015
Tweet

More Decks by Cam Huynh

Other Decks in Programming

Transcript

  1. before(:talk) { about(:me) } Huỳnh Quán Cẩm. bug creator @

    dadadee.com. die-hard Chelsea supporter. @huynhquancam | [email protected]
  2. what.is?(:monkey_patching) The dynamic modifications of a class or module at

    runtime. * A common pattern shared across Ruby community.
  3. the (:good) -> { side } extremely convenient, especially for

    hot-fix. shorter code writing. nicer DSL syntax.
  4. the -> (dark) { side } global namespace pollution. codes

    are more difficult to debug and understand. poor upgradeability. race condition of libraries. …
  5. MP.without { making.a(mess) } Fork the library on Github. Put

    them into a module. Standardise the way of your monkey-patching files structure.
  6. MP.without { making.a(mess) } Fork the library on Github. Put

    them into a module. Keep them together. Use Ruby refinements.