TeensyMud - 'A ruby mud server.'

Subject: Using @db
Subject: Using @db
Author: Massaria
Posted: 03/01/2006 02:05AM

I know this problem stems from yet another attempt to violate the interaction betweeen Classes, but I just can't seem to grasp these errors.

I'm simply trying to seach the database for an id, from within a command file.

I can't do 'find_player_by_name', and neither am I able to use the methods in yamlstore.rb (at least not 'each').

Please, expose my ignorance and tell me how to access these methods.



$engine.world.db. seems to work.

I hope to one day understand why too ;-)

Subject: Using @db
Author: Tyche
Posted: 03/01/2006 04:48PM

Massaria wrote:
> Ah!
> $engine.world.db. seems to work.
> I hope to one day understand why too ;-)

Maybe to illustrate is best done through an example?

Instance method.

irb(main):001:0> class A
irb(main):002:1> def get(oid)
irb(main):003:2> end
irb(main):004:1> end
=> nil
irb(main):005:0> A.get(1)
NoMethodError?: undefined method `get' for A:Class
from (irb):5
irb(main):012:0* a = A.new
=> #
irb(main):013:0> a.get(1)
=> nil

Class method:

irb(main):006:0> class A
irb(main):007:1> def A.get(oid)
irb(main):008:2> end
irb(main):009:1> end
=> nil
irb(main):010:0> A.get(1)
=> nil

@db on World is an instance of the YAMLStore. To use any of the methods in YAMLStore you need an instance of it. And you need a the particular instance that's on the instance of World that's on the instance of the Engine ($engine), thus $engine.world.db