private inner class

  • Thread starter John-Mason P. Shackelford
  • Start date
J

John-Mason P. Shackelford

In ruby is it possible to have a private innner class? Using private
method doesn't appear to work.

class A
private
class B
def hw
'hello_world'
end
end
end

A::B.new.hw # => 'hello world'



John-Mason Shackelford

Software Developer
Pearson Educational Measurement

2510 North Dodge St.
Iowa City, IA 52245
ph. 319-354-9200x6214
(e-mail address removed)
http://pearsonedmeasurement.com
 
G

Glenn Parker

John-Mason P. Shackelford said:
In ruby is it possible to have a private innner class? Using private
method doesn't appear to work.

class A
private
class B
def hw
'hello_world'
end
end
end

A::B.new.hw # => 'hello world'

p A::B.new.hw => "hello world"
 
G

gabriele renzi

Glenn Parker ha scritto:
p A::B.new.hw => "hello world"

I guess he meant this is not private.
Anyway, that would be a "yes and no". You can't do that way since
constants are public, but you can use a class variable, wich is private:
=> "yuk"
 
G

Glenn Parker

Robert said:

Sorry, I completely misunderstood John-Mason's question. I thought he
wanted A::B.new.hw to work, but that maybe he was confused because
nothing was being printed. Now I understand that he actually wanted it
to fail!
 

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
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top