What is 'Monkey Patching,' and what are the safer alternatives provided by modern Ruby?

Last updated 27 June 2026

  • Monkey patching reopens an existing class to add or change methods at runtime. The change is global and can collide with other gems or future versions.

  • Refinements (refine + using) scope a change lexically to where it's activated.

  • A module with prepend wraps a method and calls super instead of overwriting it. Composition (wrapping the object in your own class) avoids altering the original at all.

  • https://www.turing.com/interview-questions/ruby
  • https://www.youtube.com/watch?v=lkunzd5uDrw
  • https://blog.jacobvosmaer.nl/0004-ruby-scheduler-interaction/
  • https://wohotech.in/coding/top-java-interview-questions
  • https://jetthoughts.com/blog/ruby-3-4-yjit-performance-guide/
  • https://speed.ruby-lang.org/
  • https://flexiple.com/python/interview-questions
All Ruby interview questions