Forum: Ruby class methods and protected instance methods

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Gregory S. (Guest)
on 2006-05-03 20:57
(Received via mailing list)
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()
    return newfoo

  def initialize
    # no magic here


  def init_magic
    # something magical

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
seeing? I'm not looking for a workaround; I've already found a better
of doing what brought this to my attention. I am just looking for an

Patrick H. (Guest)
on 2006-05-04 17:49
(Received via mailing list)
On 5/1/06, Gregory S. <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.

This topic is locked and can not be replied to.