Skip to content

Don't monkeypatch Hash #3

Open
Open
@danleyden

Description

@danleyden

fog-softlayer/lib/fog/softlayer/ext/hash.rb provides a monkeypatch on hash to add functionality to that class.

Adding a monkeypatch like that means that all users who include your gem end up having that method on the Hash object, which may interfere with their own overriding methods or interfere with similar things done in other libraries. This violates the principle of least surprise...

String is also monkeypatched, but in a less dangerous way. Because the additional methods have names that are very specific to this library, it is much less likely that they would interfere.

One possible way to fix this with minimal impact to the gem would be to use refinements which will only add the methods to the classes within the lexical scope where they are included (i.e. they wouldn't be used outside this gem unless somebody explicitly requests them)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions