2 ms·
That's just horrible. You just changed behavior globally.
by the_mitsuhiko 12y ago
That's just horrible. You just changed behavior globally.
- moe 12y agoI didn't say it's pretty. Merely chose that example to point out the absurdity of challenging Ruby on the grounds of flexibility (of all things). Obviously, in a real program you'd rather write a custom sort-comparator, use a wrapper-class, or monkey-patch only the specific NaN instances that you want to change the behaviour of.
- bshimmin 12y agoOr use refinements.
- klibertp 12y agoNo, it's beautiful. Being a Python programmer it took me a long time to appreciate the power to do things like this. Learning Elisp, Smalltalk, Io and JavaScript (well) certainly helped. Also, of course you can scope such a change however you want, for example to a single block (and with threadlocals it's going to be mostly safe).
- dkarapetyan 12y agoHe was just demonstrating that it is possible. You can in fact alias the method, do the sorting, and then restore the previous functionality of throwing errors. Plus, someone already mentioned that you can also use refinements.