0

I cannot determine why this is not working. I throw it in irb and it works fine.. Please let me know if you see the issue

My Code:

class Player
  def play_turn(warrior)
    @warrior = warrior
    @turn ||= 0

    puts @warrior.look

    if @warrior.look.include?("Wizard")
      @warrior.shoot!

Output of puts which is an Array:

nothing
Captive
Wizard

For some reason it will not do the shoot, this if statement returns false.. Thanks!

4

1 回答 1

5

@warrior.look returns an array of Space objects and not strings. Only puts converts them to string that is why your .include?("Wizard") is not working.

So you can convert the Space objects to string before your .include?("Wizard") or you need a condition which works on Space object like using the Space#enemy? or Space#unit methods:

if @warrior.look.any? { |space| space.enemy? }
      @warrior.shoot!
于 2013-08-11T06:42:49.267 回答