How to do the wrong thing the right way ;-)
Published almost 6 years ago
Ruby never stops to surprise me.
class Object def _(method, *args) if self.class.private_instance_methods.include?(method.to_s) send(method, *args) else raise "Stop acting like hasslehoff!!" end end end class Hello def hey puts "New world order!" end private def secret(foo, bar) puts "#{foo} is not #{bar}" end def hasslehoff puts "acts_as_hasslehoff ftw!" end end h = Hello.new h._ :secret, "hello", "world" h._ :hasslehoff h._ :hey, "srsly?" rescue puts "yay!"
Call the private methods all you want. But at least do it the right way ;-)