On 15/12/05, ajmayo / my-deja.com <ajmayo / my-deja.com> wrote:
> Also, I presume Ruby is a forward-referencing language only, unlike
> Javascript, where I can declare a function after code which calls it.
> Ruby didn't seem to like that much.

Ruby will usually wait until code is actually run to check if
something is defined.  So, if Ruby says that something doesn't exist
in your code, the code is being run right then (like when you do stuff
inside class x ... end, all of it is run right away).  So, you can do
things like have two classes that each make an object of the other
class, all without needing things like prototypes in C :

class A
  def make_it
    @b = B.new
  end
end

class B
  def make_it
    @a = A.new
  end
end

This is because those class names are just global variables
(technically, constants that can be changed) that have a classes
assigned to them.  Thus, you can do weird things like assign classes
to variables :

a = Hash
h = a.new

This allows you to do things like pass classes into methods so that
those methods can do whatever they want with the classes.

Hope this helps.