Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Every Ruby object is an instance of a singleton class that inherits from its declared class.

    # o is an instance of its singleton class,
    # which inherits from Object
    o = Object.new
It is like saying:

    class Object
      def self.new(*args, &block)
        # Class.new(Object) creates an anonymous
        # subclass of Object
        Class.new(Object).new(*args, &block)
      end
    end
except with built-in language support. Instead of having to do this manually, every object gets a singleton.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: