Hi All
Now another hitch:
1 class Person
2 attr_reader :genre, :style
3 protected :genre
4 private :to_s
5 def psedonym
6 @name
7 end
8
9 def to_s
10 “just another person”
11 end
12 #private :to_s
13 end
14
15 p= Person.new
16 puts p
17 puts “********”
18 puts p.to_s
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CASE I
With the above class the output comes out to be:
ruby yet.rb
just another person
just another person
CASE II
Now when I comment Line 4 and Uncomment Line 12, the output comes to be:
ruby yet.rb
just another person
yet.rb:18: private method `to_s’ called for just another person:Person
(NoMethodError)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
THE HITCH
In first case it appears that that private declaration had no effect,
thus the textual position matters here; If this is really so, can anyone
explain why??
AND
In second case why the private declaration had no effect on
puts p
when in fact (this is what i infer) it uses the same method which
puts p.to_s
uses.
Can anyone Explain this bias???
Thanks
Raja