mardi 4 août 2015

Ruby2.0: What is the difference between Ruby Refinements and Monkeypatches?

I could do some simple task in either way,

Refinements

module StringRefinements
  refine String do
    def do_something
      "bla bla bla..."
    end
  end
end

So, I can use do_something method wherever StringRefinements module was using.

Monkeypatch

class String
  def do_something
    "bla bla bla..."
  end
end

I would like to know the difference between Ruby's new concept Refinements and the one Monkeypatch. And what are the advantages of using Refinements over Monkeypatch?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire