All pastes #372452 Raw Edit

Mine

public text v1 · immutable
#372452 ·published 2007-02-26 01:44 UTC
rendered paste body
=begin
	This is my first assignment for Scripting Academy. I'm going to demonstrate
	my knowledge of Ruby here. I hope this is good enough!
=end

# Let's start with a class

# This may be a working class later, but now it's the framework for a menu
class MyMenu
	attr_accessor :cursor_position
	attr_accessor :items
end

# Now I'm going to create a new object and set some values
menu1 = MyMenu.new
menu1.cursor_position = 0
menu1.items = ["Items", "Skills", "Exit"]

# Finally, time for some local variables
some_useless_variable = 2
my_name = "CompletelyAnon"

# And instance variables...
@location_x = 12
@location_y = 12

# Let's assume we have a battle class and we have these variables
@@battles_fought = 100
@@battles_won = 1

# It's time to go global
$a_global_variable = 15
$menu2 = MyMenu.new

# You are NOT changing these constants
One_Plus_One = 2
Idiots_One_Plus_One = 3

# Time to hash it up
my_hash = { "A Key" => "A Value", "Something" => "Something Else" }

# p is a nice function
p menu1		-> #<MyMenu:0x4033f8d8 @items=["Items", "Skills", "Exit"], @cursor_position=0>
p @@battles_fought	-> 100
p my_hash	-> {"A Key"=>"A Value", "Something"=>"Something Else"}

# But so is print
print $menu2	-> #<MyMenu:0x4033f7ac>112
print @@battles_won 	-> 1
print @location_x	-> 12