4 ms·
This is fine if this will be only used by you. Now what if you started distributing this, say in a gem? The person using your software may already have a to_sen
by mncaudill 18y ago
This is fine if this will be only used by you. Now what if you started distributing this, say in a gem? The person using your software may already have a to_sentence monkey-patch in place, and your gem they are using interferes with that.
Also, what if someone monkey-patches a core method of Array? Any one else consuming this script has a broken build they need to deal with it. Most of the time, these collisions do not occur, but sometimes they do and and often in subtly and hard-to-detect ways.
- sho 18y agoOverriding core methods is a definite no-no. And if you were actually going to distribute something, you'd probably have a new class descending from Array and add your methods to that. But for private code - you've got a bunch of Arrays, you want them to output something interesting - what's wrong with that?
- mncaudill 18y ago"But for private code...what's wrong with that?" Reread my first sentence. I see nothing terribly wrong with monkeypatching for personal projects.