class Player
def getsaves
print "Saves: "
saves = gets
end
def initialize(saves, era, holds, strikeouts, whip)
end
end
I have the code above...lets say I then write.
j = Player.new(30, 30, 30, 30, 30)
I want to access the saves variable in getsaves
When I am outside the class scope, how do I do this?:
puts saves variable that is inside getsaves
As you've written it, not only is the
saves
variable inaccessible from outside the class scope, it goes out of scope at the end of thegetsaves
method.You should do something like this instead:
Now you can simply use
j.saves
to access the@saves
variable.