Ruby Hangman for 7 Feb 2012

3 views
Skip to first unread message

markus

unread,
Feb 7, 2012, 10:34:31 AM2/7/12
to pdxruby
(The story that follows isn't technically true, but it's reasonably
truthy--I've just made some simplifications & changed some details for
various reasons--not the least of which is to make it into a puzzle).

I say that I never use my hangman tricks in a production environment,
which is true, but I do occasionally dip into my bag of tricks for
testing, debugging, or prototyping purposes.

A few weeks ago I was helping a client evaluate the suitability of
DataMapper's dm-rest-adapter. It wasn't a drop-in solution, but the
question of whether it could be made to work with a few strategic bug
fixes (and subsequent pull requests) was still open.

We decided to do a time-boxed exploration before deciding on the
feasibility of playing fork-and-fix. We started by adding a file called
dm-rest-monkey-patches.rb (initially empty) and then just iteratively

1) running the app
2) seeing what broke
3) tracing down the problem
4) adding a monkey patch to get past it
5) goto 1

This worked well for the first half dozen snags or so, until we
discovered that, while you could specify the serialization format as
either json or xml, you always got xml. It turned out that this was due
to the hard coded application of "to_xml" in various places in the
library.

They were scattered enough (and embedded in in various methods) that it
didn't make sense to monkey patch around all the uses.

I considered walking the class hierarchy and overriding the to_xml
methods with to_json on all the classes, but that seemed...a bit too ham
handed. A moment's thought led me to a much more elegant (though still
hangman worthy) solution, suitable for getting on with our testing but
as usual not something I'd condone in production:

#
# Now THIS is what I call a monkey patch!
#
__________
_________________dm-rest-adapter_adapter_______
______to_xml___to_json__

See you all tonight!

-- M


Reply all
Reply to author
Forward
0 new messages