noizZze

Ruby: Testing Private and Protected Methods

Every time I think I have already seen all the major wonders of Ruby, I stumble upon something like this.

Ruby continues to teach me one important lesson – BE CURIOUS. I am… by nature, but I still notice a tremendous change in working habits – following what-if and is-it-possible models more often than usual. I used to evaluate the answers on these questions basing on my knowledge of the language. With Ruby things start to look different. The flexibility of syntax is so high that I seem can’t build the complete mental model of the language (like an interpreter embedded in a head) and quickly answer what’s possible and what’s not. It makes me to go Googling more and more to find existing solutions. Sometimes (as in example above) they are so elegant that it makes me cry.

Old man’s note: This workaround for calling private / protected methods smells to me. How they different from public methods then if all you need to figure out how to call that you weren’t supposed is only two more grams of brain cells. Hmmm. Do I get it wrong?