A
A
Alexander2014-12-12 11:35:54
ruby
Alexander, 2014-12-12 11:35:54

What is the difference between private_class_method and private?

What is the difference between private_class_method and private?
if you replace line 10 with this, private :newit gives an error `private': undefined method `new' for class `Point3D'

class Point3D < Point
  def initialize(x, y, z)
    super(x, y)
    @z = z
  end
  def self.fabric(x,y,z)
    new(x,y,z)
  end
  private_class_method :new  # если заменить на  private :new
end

po1 = Point3D.fabric 4,6,5
p po1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai, 2014-12-12
@j_wayne

apidock.com/ruby/Module/private_class_method
private_class_method makes a class method private (strange, isn't it?)
private with an argument - an object method (instance method)
The error is quite reasonable - there is no such instance method in the Point3D class, only a class method.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question