账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    关于Ruby 的NoMethodError问题
    29
    0

    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

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部