2012-02-23 19 views
0

私は単純なエラーがあることを知っていますが、私はそれを見つけることができません。私はModules/Mixinsを初めて使用しています。どんな助けでも大歓迎です。 Playerクラスの内部ときはinclude ValueRuby Mixin Undefined Method

module Value 
    def this_is 
    puts "#{self.players_hand} is the players hand" 
    end 
end 

require './value.rb' 

class Player 
    include Value 
    attr_accessor :players_hand 

    def initialize 
    @players_hand = 0 
    end 

    def value_is 
    Value.this_is 
    end 
end 

require './player.rb' 

class Game 

    def initialize 
    @player = Player.new 
    end 

    def start 
    puts @player.players_hand 
    puts @player.value_is 
    end 
end 

game = Game.new 
game.start 

答えて

1

...私のモジュールとクラスです。ここ...されている

undefined method `this_is' for Value:Module (NoMethodError) 

しかし、方法があるように見えます:私はこのエラーを取得しておきます Valueモジュールのメソッドを Playerクラスの一部にしているので、 this_isメソッドは名前空間にはなりません。

def value_is 
    Value.this_is 
end 

へ:

def value_is 
    this_is 
end 
+0

グレート説明私たちはこの方法を変更する必要がある、ということを知って!ありがとう、@ctcherry – Alekx