关于Ruby 的NoMethodError问题

class Person #继承该副类
def initialize(name,age)

@name=name
@age=age
puts "This is the Father Class #{@name},#{@age}"

end

def Call1

puts "The name is #{@name},and the age of him is #{@age}"  #defination

end

def Function1

puts "Sleeping...Age:9"

end

def getPublic

puts "此处调用私有方法:"
self.Function1

end

private :Function1
end

father=Person.new("charles",23)
father.getPublic

出现问题如下:
This is the Father Class charles,23
/home/rcctp00013258/RubymineProjects/Project1/Succeed/father.rb:20:in `getPublic'此处调用私有方法:
: private method `Function1' called for #<Person:0x000000015c7668 @name="charles", @age=23> (NoMethodError)

from /home/rcctp00013258/RubymineProjects/Project1/Succeed/father.rb:27:in `<main>'

Process finished with exit code 1

阅读 1.7k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进