当前位置: 移动技术网 > IT编程>脚本编程>Ruby > Ruby定义私有方法(private)的两种办法

Ruby定义私有方法(private)的两种办法

2017年12月08日  | 移动技术网IT编程  | 我要评论
#定义私有方法途径1: class c def public_method private_method end def pri
#定义私有方法途径1:
class c
  def public_method
    private_method
  end
 
  def private_method 
  end
 
  private :private_method #定义方法为私有
end
 
#定义私有方法途径2:
class c
  def public_method
    private_method
  end
 
  private
  def private_method #定义私有方法
  end
end
 
c.new.public_method

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网