How to create a private class method?

后端 未结 8 1324
北荒
北荒 2020-12-02 04:43

How come this approach of creating a private class method works:

class Person

  def self.get_name
    persons_name
  end

  class << self

    private         


        
8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 04:51

    As of ruby 2.3.0

    class Check
      def self.first_method
        second_method
      end
    
      private
      def self.second_method
        puts "well I executed"
      end
    end
    
    Check.first_method
    #=> well I executed
    

提交回复
热议问题