# Class methods and protected instance methods

**URL:** <https://www.ruby-forum.com/t/class-methods-and-protected-instance-methods/59347>\
**Category:** Ruby\
**Created:** [May 3, 2006, 6:57pm UTC](https://www.ruby-forum.com/t/class-methods-and-protected-instance-methods/59347 "2006-05-03T18:57:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pie-r-squared](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c77e96/32.png) [@pie-r-squared](https://www.ruby-forum.com/u/pie-r-squared)\
**Post date:** [May 3, 2006, 6:57pm UTC](https://www.ruby-forum.com/t/class-methods-and-protected-instance-methods/59347/1 "2006-05-03T18:57:53Z")

</div>

I would have thought that a class method context would be able to call  
protected methods on an instance of that class. That does not seem to be  
the case:

class Foo  
def self.create\_with\_magic  
newfoo = new()  
newfoo.init\_magic  
return newfoo  
end

def initialize  
# no magic here  
end

protected

def init\_magic  
# something magical  
end  
end

foo = Foo.create\_with\_magic #this will raise an exception

Is this just an oversight? A bug? Is there a rationale for it that I’m  
not  
seeing? I’m not looking for a workaround; I’ve already found a better  
way  
of doing what brought this to my attention. I am just looking for an  
explanation.

–Greg

---

<div class="post-metadata">

**Author:** ![pie-r-squared](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c77e96/32.png) [@pie-r-squared](https://www.ruby-forum.com/u/pie-r-squared)\
**Post date:** [May 4, 2006, 3:49pm UTC](https://www.ruby-forum.com/t/class-methods-and-protected-instance-methods/59347/2 "2006-05-04T15:49:02Z")

</div>

On 5/1/06, Gregory S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

This is what is expected. Ruby is not C++/Java and its object model is  
quite different. In particular as Class objects are first class  
objects, they do not bestow any special access rights to other  
objects, including instances of themselves.

pth
