You didn't include any test data, so I wrote a little program that created
a phone book and stored it and then a second that unloaded it. Your
load/unload methods had a number of errors in them that I've corrected so
this is a working version.
I did not tackle the unknown method issues because I really don't
understand what you are trying to accomplish. I suggest forgetting
whatever you've done with that and first define how you really want this to
behave and I'll help you to an implementation. What you are doing now is
not on the right path.
-- Create a simple phonebook
#!/usr/bin/rexx
book = .phonebook~new
book['Jenny'] = .contact~new("Jenny", "Jenny Jenny", "867-5309")
book~unload('Phone.book')
::requires 'phonebook3.cls'
-- load a phone book a show that it works
#!/usr/bin/rexx
example = .Phonebook~new
say example ~ type
example ~ load('Phone.book')
do e over example -- Iterate over the collection
say example[e]
end e
say -- Index lookup is case sensitive...
say example['Jenny'] -- Exact match
::requires 'PhoneBook3.cls'
-- the corrected phone book class
---------------------------------------------------------------------------------
Implementation of a phone book entry:
--::class contact public
::attribute name::attribute fullName::attribute phoneNumber
::method init public
expose name fullName phoneNumber
use arg name,fullName,phoneNumberreturn
::method type publicreturn 'a Phone Book contact'
::method string public
expose name fullName phoneNumber
say name ~ left(12) fullName ~ left(25,'.') phoneNumberreturn
::method format public
expose name fullName phoneNumber
EoT = '04'x
record = name ~ strip || EoT,
|| fullName ~ strip || EoT,
|| phoneNumber ~ stripreturn
record---------------------------------------------------------------------------------
Implementation of a phone book directory:
--::class PhoneBook public subclass directory::method type
public
trace normalreturn 'a Phone Number directory'
::method load public -- Read contacts from an external file.
expose name fullName phoneNumber
EoT = '04'x
use strict arg fileName,mode = 'read shared'
fileStream = .stream ~ new(fileName)
fileStream ~ open(mode)
do while fileStream ~ lines > 0
parse value fileStream ~ lineIn with name (EoT) fullName (EoT) phoneNumber
self ~ put(.contact ~ new(name,fullName,phoneNumber),name)
end
fileStream ~ closereturn
::method unload public -- Write contacts into an external file.
expose name fullName phoneNumber
EoT = '04'x
use strict arg fileName,mode = 'write replace'
fileStream = .stream ~ new(fileName)
fileStream ~ open(mode)
do contact over self~allItems
fileStream ~ lineOut(contact ~ format)
end
fileStream ~ closereturn
------------------------------------------------------------------------------
Time is money. Stop wasting it! Get your web API in 5 minutes.
www.restlet.com/download
http://p.sf.net/sfu/restlet
_______________________________________________
Oorexx-users mailing list
Oorexx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-users