S
slowhog
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/ru...-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"
}
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/ru...-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"
}