Send to access private members

I’m a confused about why the following code works:

class Foo
private
def hello
puts “hello”
end
end
f = Foo.new
f.send(:hello)

whereas
f.hello will obviously fail.

I have tried this with private member setting as well and it also works.
Is send supposed to operate this way? The rdoc for it don’t seem to
mention this. Thanks!

Hi –

On Sat, 6 Jan 2007, David W. wrote:

whereas
f.hello will obviously fail.

I have tried this with private member setting as well and it also works.
Is send supposed to operate this way? The rdoc for it don’t seem to
mention this. Thanks!

Yes, send ignores the private status. In 2.0 there will be a version
of send that doesn’t and one that does. It’s not certain what they’ll
be called (but if you have nothing to do for the next week or two you
can look at the discussions about it :slight_smile:

David