What are Refinements and how do they solve the problems of Monkey Patching?

Last updated 27 June 2026

  • Refinements are lexically scoped patches: declare them with refine SomeClass inside a module, and activate them only where using is called (to the end of that file/scope).

  • They fix monkey patching by being scoped, not global. Code that doesn't opt in sees original behavior, and the dependency is explicit at the point of use.

  • Caveats: more verbose, and some dynamic dispatch (e.g. send) may not see refinements.

  • https://medium.com/@hpultimatemedia/advanced-ruby-programming-tutorial-9bebc6335c21
  • https://hellointern.in/blog/ruby-interview-questions-and-answers-for-2-years-experience-28493
  • https://www.reddit.com/r/rails/comments/1eb4wfx/ruby_on_rails_role_interview_what_questions_to/
  • https://news.ycombinator.com/item?id=42495135
  • https://www.adaface.com/blog/ruby-on-rails-interview-questions/
  • https://lemon.io/interview-questions/python/
  • https://www.kore1.com/hire-elixir-developers-2026/
  • https://www.testgorilla.com/blog/elixir-developer-interview-questions/
  • https://pragtob.wordpress.com/
All Ruby interview questions