public Method

Module.private_class_method(...)

mod.private_class_method(symbol, ...)    mod

Makes existing class methods private. Often used to hide the default constructor new.

class SimpleSingleton  # Not thread safe
  private_class_method :new
  def SimpleSingleton.create(*args, &block)
    @me = new(*args, &block) if ! @me
    @me
  end
end

Source Code

/*
*  call-seq:
*     mod.private_class_method(symbol, ...)   => mod
*  
*  Makes existing class methods private. Often used to hide the default
*  constructor <code>new</code>.
*     
*     class SimpleSingleton  # Not thread safe
*       private_class_method :new
*       def SimpleSingleton.create(*args, &block)
*         @me = new(*args, &block) if ! @me
*         @me
*       end
*     end
*/

static VALUE
rb_mod_private_method(argc, argv, obj)
   int argc;
   VALUE *argv;
   VALUE obj;
{
   set_method_visibility(CLASS_OF(obj), argc, argv, NOEX_PRIVATE);
   return obj;
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.