3 ms·
Right, that’s monkey patching. You run into the real problems when you have multiple people wanting to add them. Ruby isn’t alone in supporting this functional
by emodendroket 3y ago
Right, that’s monkey patching. You run into the real problems when you have multiple people wanting to add them.
Ruby isn’t alone in supporting this functionality (you can fiddle with JavaScript prototypes, for instance), but I think it is unique how much it is encouraged (at least in Rails world). I think extension methods are a much better model to achieve something similar.
- shagie 3y agoThere are also some really weird/powerful/voodoo things that you can do when that is combined with the first class environments. The "why Scheme didn't do this": First-class environments - http://funcall.blogspot.com/2009/09/first-class-environments.html http://funcall.blogspot.com/2009/09/first-class-environments... why Ruby did (and wasn't a good idea): Ruby Conf 2011 Keeping Ruby Reasonable https://youtu.be/vbX5BVCKiNs https://youtu.be/vbX5BVCKiNs Consider where you can slip in a block invocation and the following code: def mal(&block) block.call block.binding.eval('a = 43') end a = 42 puts a mal do puts 1 end puts a and that that means that you've got full access to be able to inspect and manipulate all of the variables in scope at the time of the invocation. While that example is rather obvious, it can be done much more subtly too. The power of ruby to do meta programming and by extension some really neat DSLs also provides it with some dangerous tools that are otherwise rather difficult to track down.