battleship=Array.new(9){Array.new(9)} #def to allow players to be able to call for the board def board battleship[0][1]="A" battleship[0][2]="B" battleship[0][3]="C" battleship[0][4]="D" battleship[0][5]="E" battleship[0][6]="F" battleship[0][7]="G" battleship[0][8]="H" battleship[0][0]=" " battleship[1][0]="1" battleship[2][0]="2" battleship[3][0]="3" battleship[4][0]="4" battleship[5][0]="5" battleship[6][0]="6" battleship[7][0]="7" battleship[8][0]="8" unknown="~" for x in (1..8) for y in (1..8) battleship[x][y]=unknown end end battleship.each do |myval| puts myval.to_s end end puts board
I'am new to programming and to ruby code, i'm having a hard time using the def method to use to call it up and display it. I get this error code:
C:/Users/Unknown/AppData/Local/Temp/rbB39C.tmp:4:in `board': undefined local variable or method `battleship' for main:Object (NameError)
from C:/Users/Coolwave/AppData/Local/Temp/rbB39C.tmp:31:in `<main>'
Any help would be great!! thanks