# syntax for defining a class is simple: class class MyClass # class vars are defined with two @@ symbols @@classvar = nil # the constructor can take any number of paramters, and is named initialize def initialize(param) # a call to the super is done as the first line in your constructor #super(param) # membervars are defined with an @ symbol @membervar1 = nil @membervar2 = nil end # a method, called as instance.method() def method # self is ruby's form of "this" self.membervar1 end # this is an accessor method in ruby def membervar1 @membervar1 end # this is a mutator method in ruby def membervar1=(newval) @membervar1 = newval end # overloading the - operator def -(other) end # private methods def privatemethod1 end def privatemethod2 end private :privatemethod1, :privatemethod2 # protected methods def protectedmethod1 end def protectedmethod2 end protected :protectedmethod1, :protectedmethod2 # class method def MyClass.classMethod end # private class method def MyClass.privateClassMethod end private_class_method :privateClassMethod end # create an instance instance = MyClass.new( "param" ) # lets add a method to instance on the fly! def instance.singletonMethod puts "This will only belong to THIS instance of MyClass" end instance.singletonMethod # we can also add methods to en entire class at runtime class MyClass def newMethod puts "This will belong to all instances of MyClass" end end instance.newMethod