From: slowhog Date: 2010-01-26T15:57:01+09:00 Subject: Is there a way to have instance_eval cannot call private/protected method? Hi, Is there any mechanism to do what instance_eval but honor the visibility? I want to something like following, but would like the block passed to real_object can only only have access to public methods. I did a little search, seems like 1.8.5 does that, but was changed in 1.8.6[1]. While I don't know the history, I am interested to learn about the rational, and if there is a replacement for that behavior. Thanks in advance, Henry [1] http://jamesgolick.com/2007/9/28/ruby-1-8-5-_eval-methods-are-subject-to-access-modifiers-on-self.html class RealObject private def method1(param) puts "Test Method 1: #{param}" end public def method2(param) puts "Test Method 2: #{param}" end end def real_object(&block) x = RealObject.new x.instance_eval &block end real_object { method2 "m2" method2 "m2.2" method1 "please fail me" }