From: Iain Barnett Date: 2012-06-21T21:33:07+09:00 Subject: Re: Looking for a better way to add a method to a core class than monkey patching Ok, sorry to be the cause of confusion and/or consternation! Let me preface this by saying that I do understand the dangers (I hope), but that sometimes it is still appropriate so I wished to find out what the 2012 view point is on the implementation. I take the view that it's hard to ask a stupid question, and it's good to revisit things that you feel are basics or "done" to improve or perhaps change (or just find out you're still right!:) Things change, and I don't know everything (/much). Having said that, I can understand why anyone would give a strong "non!" to the idea without any specifics. I hope that was diplomatic enough :) I spliced together two libraries that deal with Postgres' HStore document format (a No SQL field, essentially) into a new one as an update to a Sequel extension. I got it to pass the specs and do what I wanted, put in the pull request, and the maintainer (among other things) warned me that he'd prefer it if the core classes weren't opened up. This prompted the question, though I realise I can do this other ways I'd also like to know the best way to do it this way - I was more interested in the general point than the specific solution. The decision to monkey patch was actually in one of the libraries I took from, I took their ball and ran with it until the specs passed and then put in the pull request. If it had been accepted then I'd have probably worked on it some more. If you're still interested, the code in question is at https://github.com/yb66/sequel/blob/master/lib/sequel/extensions/pg_hstore.rb. The method(s) would be a Hash#to_hstore and a String#from_hstore. When I get a chance I'm going to make it into its own gem (on the advice of the maintainer) and I'll consider whether it's a good idea to continue with the monkey patches. Regards, Iain