send to access private members

D

David Weldon

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!
 
D

dblack

Hi --

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!

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 :)


David

--
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
(See what readers are saying! http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,222
Messages
2,571,138
Members
47,755
Latest member
Grazynkaa

Latest Threads

Top