0
所以,我知道有一個簡單的錯誤,但我似乎無法找到它。我第一次使用Modules/Mixins,任何幫助將非常感謝。我不斷收到此錯誤:Ruby Mixin未定義方法
undefined method `this_is' for Value:Module (NoMethodError)
但它看起來像的方法是存在的......這就是我的模塊和類...
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
很好的解釋!謝謝@ctcherry – Alekx 2012-02-23 04:38:57