Trying to get symbols that are stored in a hash into an array, help needed.

The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Trying to get symbols that are stored in a hash into an array, help needed.

Hey guys I'm pretty new to Ruby and programming in general. I'm reading the Ruby book "Beginning Ruby - From Novice To Professional" and I'm doing one of the included projects - building a basic text adventure.

I'm done with the text adventure but now I want to expand the features with some of my own methods but I'm running into problems.

What I want to do is to have a method that prints out in which directions (south, north, east, west), from any given room, there are exists to other rooms.

To do this I want to iterate through a hash with the each method and store every key (not value) in an array so that I then can see how many exits there are to the room where the player is at and print out a message of those exits. The keys are symbols.

class Room
#Creates the objects variables that store infromation about the Room.
attr_accessor :reference, :name, :description, :connections#Sets the information that is set when the object is created to the object variables for storage.def initialize(reference, name, description, connections)@reference = reference
@name = name
@description = description
@connections = connections
end#Defines a method that returns the full description of the Room object. def full_description
@name+"\n\nYou are in "+@descriptionendend

@connections is a object variable that stores the hash that contains directions and locations like so for example: {:east => :large_room}

So I managed to store the directions of any given Room object with this line:

This isn't ideal beacuse it just prints the directions with a comma afterwards. On one room object I have the output is this: "You see exits to your west, north, eats,"

I want it to print "You see exits to your west, north and east" but I can't figure out how to do that unless I code one separate elsif for every possible number of directions, and that's not a good way.
Is there some way I can get that output and still use an interator?