开发者

Uninitialized Constant error

When I run the following code I'm getting an error that reads "fig_match:rb:5:in '': uninitialized constant Match::Fig (NameError) from fig_match.rb:4:in"

I wa开发者_开发知识库s in the midst of testing my setup and battle methods, which is why I have the setup and match calls after my variable setters in the Match class.

require_relative = 'fig_user.rb' #class name is Fig within fig_user.rb

class Match
    fig1 = Fig.new
    fig2 = Fig.new
    go = 0
    winner = nil

    setup(Bob, Sam)
    match.battle

    def setup(name1, name2)
    #set names
    @name1 = fig1.name
    @name2 = fig2.name

    go = rand(2)
    end


    def battle
        if go.even?
        p fig1.name

        end
    end 

end

This is the separate class that's being referenced in the above code (not sure if it matters)

class Fig 

attr_reader :name, :power, :health
attr_accessor :name, :power, :health

deckId = @id 
name = @name 
power = @power
moves = Hash["Kick", 50, "Punch", 30]
health = 100
end


require_relative is a method. You've assigned it as a variable name. Hence, you have no Fig class in your scope.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜