7stud2
(7stud --)
1
In this script: (Attached)
For some reason, when I call print_stats, for every variable, it returns
nil? Why is this? Am I doing something wrong?
Attachments:
http://www.ruby-forum.com/attachment/7297/closercomp.rb
···
--
Posted via http://www.ruby-forum.com/.
Try assigning your initial values to their respective instance variables.
class Player
def initialize(saves, era, holds, k, bs, whip, name)
@saves, @era, @holds, @k, @bs, @whip, @name = saves, era, holds, k, bs, whip, name
puts "Player Loaded"
puts @saves
end
def print_stats
puts "Stats for: #{@name}"
puts "----------------"
puts "Saves: #{@saves}"
puts "ERA: #{@era}"
puts "Holds: #{@holds}"
puts "Strikeouts: #{@k}"
puts "Blown Saves: #{@bs}"
puts "WHIP: #{@whip}"
end
end
Sam
···
On 17/04/12 13:39, Solomon W. wrote:
In this script: (Attached)
For some reason, when I call print_stats, for every variable, it returns
nil? Why is this? Am I doing something wrong?
Attachments:
http://www.ruby-forum.com/attachment/7297/closercomp.rb
7stud2
(7stud --)
3
Am I doing something wrong?
You pass the arguments into the initialize() method,
but you do not assign them anywhere.
If you assing them, you can use them.
···
--
Posted via http://www.ruby-forum.com/\.