Q:

Ruby: NoMethodError on call to display method

Greeting, I just started learning Ruby a few weeks with this noob book titled Computer Science Programming Basics in Ruby. I've practiced the exercises in each chapter, haven't had too many error, but I keep getting this error in a class I wrote up for the tic-tac-toe game in the last chapter. Here is the board.rb class file I made:
class Board
  BOARD_MAX_INDEX = 2
  EMPTY_POS = ' '

  def initialize(current_player)
    @current_player = current_player
    @board = Array.new(BOARD_MAX_INDEX + 1) {
      Array.new(BOARD_MAX_INDEX + 1) { EMPTY_POS }
    }
  end
end

def display
  puts "+------+"
  for row in 0..BOARD_MAX_INDEX
    print "| "
    for col in 0..BOARD_MAX_INDEX
      s = @board[row][col]
      if s == EMPTY_POS
        print col + (row * 3) + 1
      else
        print s
      end
      print " | "
    end
    puts "\n+------+"
  end
end     

The class runs fine, but this is the error message in irb when I attempt to access 
the display method call:
irb(main):004:0> require '/home/nick/board.rb'
=> true
irb(main):005:0> puts "Starting tic-tac-toe..."
Starting tic-tac-toe...
=> nil
irb(main):006:0> players = ['X', 'O']
=> ["X", "O"]
irb(main):007:0> current_player = players[rand(2)]
=> "O"
irb(main):008:0> b = Board.new(current_player)
=> #<Board:0x00000001c64868 @current_player="O", @board=[[" ", " ", " "], [" ", " ", "  "], [" ", " ", " "]]>
irb(main):009:0> b.display()
NoMethodError: private method `display' called for #<Board:0x00000001c64868>
from (irb):9
from /usr/bin/irb:12:in `<main>'

Why am I getting this error, what do I have to do to get it to display the board?

A:

You should put the definition of the display method inside the class:
end # of class

def display
...
end

Should be:
  def display
  ...
  end

end # of class

Hope it helps.

