November 14th, 2011
In Technology
No Comments
If you enjoy this article, see the other most popular articles
If you enjoy this article, see the other most popular articles
If you enjoy this article, see the other most popular articles
Dynamic programming asks for a dynamic mindset
(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com, or follow me on Twitter.
ruby encapsulation is for $%*t
Wow, I just learned that ruby encapsulation can be broken by simply using:my_object.send(:my_secret_private_method)
That’s kinda useful to know if you’re trying to unit test a private method, but makes the concept of encapsulation totally meaningless in ruby.Apparently, Ruby 1.9 revokes this “special” privilege, but then there are still many ways to use the power of ruby meta-programming to get to them anyway (see above link for some examples).
Paolo Perrotta writes about this in the book Metaprogramming Ruby. Page 84:
Breaking Encapsulation
At this point, you’re wearing a look of horror on your face. With a Context Probe you can wreak havoc on encapsulation! No data is private data anymore. “Isn’t that a Very Bad Thing?” you ask.
Pragmatically, there are some situations where encapsulation just gets in your way. For one, you might want to take a quick peek inside an object from an irb command line. In a case like this, breaking into the object with instance_eval() is often the shortest route.
If Ruby programmers find this alarming, then Java programmers might smugly proclaim us justly punished for our crimes. Those who enjoy the benefits of dynamic programming need to re-program their brains to accept all of what that means.
February 8, 2022 9:33 am
From Michael S on How I recovered from Lyme Disease: I fasted for two weeks, no food, just water
"Did you have Bartonella, too? Seems it uses autogenesis..."