Reputation: 2727
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!
Upvotes: 0
Views: 1627
Reputation: 139778
@warrior.look
returns an array of Space
objects and not string
s. 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!
Upvotes: 5