From: Mike Sassak Date: 2001-10-05T14:09:53+09:00 Subject: [ruby-talk:22116] Object construction with block and private methods Hi! I was reading the "Object Construction and Blocks" article on www.rubycentral.com a couple of days ago and noticed what looks to me like some odd behavior when you initialize an object with a block and instance_eval. Suppose I've got a class like so: class Foo def initialize(&block) instance_eval(&block) end def method puts "Hello, world!" end def privMethod puts "Goodbye, world!" end private :privMethod end and I go to initialize it with a block: a = Foo.new { method privMethod } When I run the code, even though "privMethod" is marked as private, it is still callable so long as it is called in the block when the object is constructed. Afterwards, if I run "a.privMethod" I get an error. But not when it's initializing. I'm guessing that Ruby allows this because instance_eval changes the value of self to be the context of the object. So while it's technically not a bug... isn't that still breaking encapsulation? Thanks, -mike