--liOOAslEiF7prFVr
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Tue, Oct 04, 2005 at 05:40:51AM +0900, Louis J Scoras wrote:
> Anyone with a bit more ruby experiance have any refactoring ideas?

Here's a sketch.  It doesn't have the full feature set (portals, etc),
but that should be easy to add.  Instead of messing around with class
variables, we simply define methods that return the values we want.
The data is stored implicitly within blocks.

class Location
  def self.description(d)
    # Even though we're using a constant method name, we use
    # "define_method" instead of "def" in order to form a closure over
    # the local variable "d".
    define_method(:describe) do
      d
    end
  end

  def self.exit_to(direction,location)
    # @exits is a member of the class object itself, not the instances
    @exits || }
    @exits[direction]  ocation
    e  exits
    define_method(:exits) do
      e
    end
  end
end

class A < Location
  exit_to :north, :b
  exit_to :east, :garden
  description "You're at point A.  It's very boring."
end

class B < Location
  exit_to :south, :a
  description "Point B is even more boring than Point A."
end

regards,
Ed

--liOOAslEiF7prFVr
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDQbSRnhUz11p9MSARAu6uAJ93tR4X5KKjXKA9TXIN0opHwozouQCgmYsu
PL0EQ3KtRkoxwOfTVkZZ6Fksh
-----END PGP SIGNATURE-----

--liOOAslEiF7prFVr--