Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #2585
| From | 7stud -- <bbxx789_05ss@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Re: private vs. protected question |
| Date | 2011-04-09 16:37 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <d4c1ef1496fe2233a1355c7812e11a19@ruby-forum.com> (permalink) |
| References | <bd7050a7923405894788738f2712f45b@ruby-forum.com> <87c34e7d5a641032304e1f716a3d831e@ruby-forum.com> |
7stud -- wrote in post #991945:
>
> The protected method rule states that you can use a receiver to call the
> method--so long as whatever object is self at that time is also an
> object of the same class as the receiver (or a parent or subclass).
I think we need to scratch '(or parent...' off the list:
class Animal
def meth(obj)
obj.bark #self=anim whose class is Animal,
end #and Animal is a parent class of obj=dog
end
class Dog < Animal
protected
def bark
puts 'woof'
end
end
dog = Dog.new
anim = Animal.new
anim.meth(dog)
--output:--
prog.rb:3:in `meth': protected method `bark' called for #<Dog:0x9f8948c>
(NoMethodError)
from prog.rb:22:in `<main>'
--
Posted via http://www.ruby-forum.com/.
Back to comp.lang.ruby | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
private vs. protected question Kaye Ng <sbstn26@yahoo.com> - 2011-04-09 05:24 -0500
Re: private vs. protected question 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-09 14:35 -0500
Re: private vs. protected question 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-09 16:37 -0500
Re: private vs. protected question 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-09 17:11 -0500
csiph-web