I'm a new coder trying to create a simple "Sword crafting" terminal app in ruby. So I've got a class with a few instanced variables I want to iterate upon depending on the users input (@strength and @speed). So here, if the user inputs that the grip is "straight" i want it to increase the instance variable "strength" by 5 - but for some reason it's not editing it no matter what I do. I've already set "strength" as attr_accessor, and i've tried making the method manually as well - but I still can't iterate upon it. What am i doing wrong?
class Weapon
attr_reader :id, :weapon_name, :guard, :blade
attr_accessor :grip, :strength, :speed
SWORDS = []
def initialize(weapon_name, grip, guard, blade)
@id = SWORDS.length + 1
@weapon_name = weapon_name
@grip = grip.to_str
@guard = guard
@blade = blade
@strength = 0
@speed = 0
SWORDS << self
end
def strength=(strength)
if @grip == "straight"
@strength = strength + 5
end
end
def to_s
"Your weapon is called: #{@weapon_name}
The grip is: #{@grip}
The guard is: #{@guard}
The blade is: #{@blade}
Total stats are: Strength = #{@strength} and Speed = #{@speed}"
end
end