NP man ^^
Also, you could check
here for a list of all globals defined by Ruby by default. Just scroll the page down, there´s a huge list there. Also,
this is the front page of the manual. You should check it, it´s wonderful as a reference basis.
But i guess you still know about it ^^
EDIT: There´s a huge difference between a class and an instantiated object FROM a class. Class inherits from Module, and the two ARE objects too. This makes it possible to call Font.default_name, for example. The main difference here is the scope of the methods. default_name has class scope, so it´ll be possible to call it directly from the class object.
Font.default_name = "blah"
. To understand it better, think about the variables´scopes (you know, local, instance and class variables...) It´ll help you visualize everything.
For example, suppose we declare a class...
At the moment of declaration, we can expect that Ruby will create a new Class object (yes, looks confusing but Class is an object! Note that
class !=
Class, because class is just a reserved word). If your code has no syntax errors, the Ruby interpreter will take all your code inside class Test/end and define a new constant called Test, and attribute to it a new class object with that code. Now, continuing our declaration:
class Test
# Defining a class method. Will work on instances and on the declaring class
def self.test_class
# Note here the use of 'self', and how it recalls to the class object we´re creating.
# as i´ve said, a class is merely an object. So, 'self' inside the class declaration
# will work like you´re calling the new class.
# This method is executed WITHIN the class, not within instances of this class.
# This is why you can make Font.something without worrying with instantiations ^^
print "Class OK"
end
# Another method to declare class methods...
def Test.test_class_2
# Same as test_class...
print "Class 2 OK"
end
# Now to the instance methods...
# This method can be called only on instance scope, or by other means, within instances
# of this class. You can´t call it from the class itself.
# Note that instance methods that call other
# methods inside it will look for methods that are in their own scope. So, they´ll
# look for instance methods first, and if they don´t find any method with the given
# name, it´ll search for class methods until it finds nothing and raises a NoMethodError.
def test_instance
test_class_2
print "Instance OK"
end
end
Noe to the test...
t = Test.new
# Calling methods from the instance
t.test_instance # ==> Class 2 OK
# ==> Instance OK
# Calling methods from the class
t.class.test_class # ==> Class OK
Test.test_class # ==> Class OK
As you can see, it´s a basic Ruby feature. Rather confusing, but does the work pretty well ^^
Well, that´s it.. I hope you got it...