Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 480981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:56:53+00:00 2026-05-13T00:56:53+00:00

Core CS question here: of the Design Patterns listed in Gamma, etc, which (if

  • 0

Core CS question here: of the Design Patterns listed in Gamma, etc, which (if any) cover monkeypatching? Additionally, for what class of problems is monkeypatching appropriate vs. subclassing? Patching bugs in core library classes is one, are there others? I hear lots of sturm und drang about monkeypatching on stackoverflow, most of you seem to have strong misgivings about it, but as a programmer I really like the ability to encapsulate generic bits of functionality and include them in my object models in rails.

Take thoughtbot-paperclip, for example, why would I want ever want to subclass that vs the monkeypatch approach that exists today?

Thanks,
-Eric

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T00:56:54+00:00Added an answer on May 13, 2026 at 12:56 am

    I don’t think monkeypatching is a Design Pattern – core class extension a language feature that they seem to ignore.

    Regarding the rest, have a look at Jeff Atwood’s views on this article on his blog.

    In his (and my) oppinion the biggest problem with monkeypatching is that it can make debugging very difficult, if it modifies existing methods – we humans can’t keep track of all the “little snippets here and there” as well as machines do. Subclasses stablish clearer separations.

    So my personal rules for monkeypatching are:

    • If you can do it without monkeypatching and it will work ok, don’t use monkeypatching.
    • You can add new methods to classes, but you can’t modify existing ones.
    • Do it in a very visible and obvious way – i.e. a file called string_extensions.rb in your /lib, not on a hidden /myvendor/submodule/se.rb .
    • Should be local; classes that don’t use a library should be unaffected.

    Now, to your example: Paperclip.

    • To my knowledge, it adds methods to your ActiveRecord classes, but doesn’t modify existing ones
    • You have to add a has_attachment directive to the classes that use paperclip, otherwise they are not affected.

    So the changes are localized and obvious (I actually think that it manages to improve debugging: is easier for us humans to read has_attachment instead of class MyModel < Paperclip::ActiveRecordWithAttachment).

    Subclassing is also a bad idea on this case because you would not be able to use paperclip in addition to another plugin that used subclasses – rails is single-inherited.

    And in Paperclip’s case, it is clearly a has_a relationship with its attachment, not a is_a one. One could argue that it would not be a proper use of subclassing.

    Finally, I’d like to point out that Paperclip requires subclassing in some occasions (you have to use subclassing in order to create a paperclip processor).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like my Core assembly to not expose a certain class and I
If I have the core of a class defined in one file as public
I have some questions about multi-threaded programming and multi-core usage. In particular I'm wondering
Using core jQuery, how do you remove all the options of a select box,
Fedora Core 9 seems to have FCGID instead of FastCGI as a pre-built, YUM-managed
The core .NET languages are integrated into VS2008 - C#, VB.NET, and C++. I'm
I have a quad core machine and would like to write some code to
I have a core file generated on a remote system that I don't have
On Fedora Core 7, I'm writing some code that relies on ARG_MAX . However,
Does Server Core 2008 support asp.net? I see references online saying that it isn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.