4 ms·
Ruby Access Control - Are Private And Protected Methods Only A Guideline?
- epochwolf 17y agotl;dr -> Ruby allows you to bypass private/protected by using Object#send class Object private def name puts "Name called" end end o = Object.new o = o.send :name # outputs "Name called" And therefore you can easily test private methods.
- dan_sim 17y agoI was just writing a bit of code in javascript (http://github.com/dsimard/jskataUndo/blob/master/jskataUndo.js http://github.com/dsimard/jskataUndo/blob/master/jskataUndo....) when I saw this post on HN. I was wondering "should I make some functions private?" and the answer is "NO". Why would I do this? Is this because I don't trust programmers? Why should I care if someone messes up with my "private" things? It's his problem after all. If you look at the source, you'll see that I have a private section at the end but it means "you don't need to use this to make it work". (note : there are some ways to make things private in javascript as I wrote there : http://www.javascriptkata.com/2009/09/23/how-to-create-an-object-with-private-variables-and-methods/ http://www.javascriptkata.com/2009/09/23/how-to-create-an-ob...)