4 ms·
Ruby String has a #to_json method I use frequently. Last week I added #from_json method to String and have already used it a lot. I love this ability to extend
by delichon 2y ago
Ruby String has a #to_json method I use frequently. Last week I added #from_json method to String and have already used it a lot. I love this ability to extend Ruby, and think the advantages outweigh the downsides, at least for pure additions rather than behavior changes to existing methods. I'd like a feature to only freeze the changes and allow additions.
- viraptor 2y agoYou can still make the change and then freeze. That's why they recommend doing it at the end of config.
- jaynetics 2y agoRegarding from_json, there's an even shorter version built in: `JSON(my_string)` Regarding redefinition of methods, Ruby can emit warnings when that happens (and you can make those fail your build for example). https://alchemists.io/articles/ruby_warnings https://alchemists.io/articles/ruby_warnings
- brink 2y agoIt's great when you're the only dev on a relatively young project.
- poincaredisk 2y ago>Last week I added #from_json method to String and have already used it a lot Why? What do you get from globally modifying a very important class, instead of just creating a regular method?