From: Peter Hickman Date: 2012-12-29T01:17:32+09:00 Subject: Re: How to run a ruby script --047d7b33db120622fd04d1ec002e Content-Type: text/plain; charset=ISO-8859-1 Well you could just place all the code between class Dungeon .. and ... end into a file called dungeon.rb and create a new file called play.rb -- play.rb #!/usr/bin/env ruby require 'dungeon' my_dungeon = Dungeon.new("Fred Bloggs") my_dungeon.add_room(:largecave, "Large Cave", "a large cavernous cave", { :west => :smallcave, :east => :kitchen }) my_dungeon.add_room(:smallcave, "Small Cave", "a small, claustrophobic cave", { :east => :largecave }) my_dungeon.add_room(:kitchen, "Kitchen", "a small kitchen", {:west => :largecave}) my_dungeon.start(:largecave) while true print "go where? " go_to = STDIN.gets.chomp my_dungeon.go(go_to) end now all you need to run it is $ ruby play.rb It will load the Dungeon class from dungeon.rb and run it (providing it is in the same directory as play.rb). --047d7b33db120622fd04d1ec002e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Well you could just place all the code between

class Dungeon
=A0.. and ...
e= nd

into a file called dungeon.rb and c= reate a new file called play.rb

-- play.rb
#!/usr/bin/env r= uby

require 'dungeon'
=

my_dungeon =3D Dungeon.new("Fred Bloggs")
my_dungeon.add_room(:largecave, "Large Cave", "a large = cavernous cave", { :west =3D> :smallcave, :east =3D> :kitchen })=
my_dungeon.add_room(:smallcave, "Small Cave", "a = small, claustrophobic cave", { :east =3D> :largecave })
my_dungeon.add_room(:kitchen, "Kitchen", "a small kitch= en", {:west =3D> :largecave})

my_dungeon.s= tart(:largecave)
while true
=A0 print "go where? &= quot;
=A0 go_to =3D STDIN.gets.chomp
=A0 my_dungeon.go(go_to)
end

now all you need to run it is

$ ruby play.rb

<= div style> It will load the Dungeon class from dungeon.rb and run it (providing it is = in the same directory as play.rb).

--047d7b33db120622fd04d1ec002e--