How to create methods programmatically - Dolphin 5.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to create methods programmatically - Dolphin 5.

Randy Manning
* How to create an (instance) method programmatically:
 "In a workspace, experiment..."

 methodName := 'time'.  "Or, multiple arguments:     'method: arg1 name:
arg2'       "
 comment := '"Answer the time now."'.
 sourceCode := '^Time now.'.
 crlf := Character cr asString,  Character lf asString.
 tab := Character tab asString.
 MyClass compile: methodName, crlf, tab, comment, crlf, crlf, tab,
sourceCode classified: 'public'.
 myInstance := MyClass new.
 "Display It"
 myInstance time




 * How to create a (class) method programmatically:
 Simply add the word 'class' to the compile:classified: method shown
above...

 Object class compile: methodName, crlf, tab, comment, crlf, crlf, tab,
sourceCode classified: 'public'.
 "Display It"
 Object time


Reply | Threaded
Open this post in threaded view
|

Re: How to create methods programmatically - Dolphin 5.

Bill Schwab-2
Randy,

If you are doing a lot of programmatic code generation, take a look at my
Dolphin goodies.  CodeGenerator (slightly misnamed) offers a preview
framework that lets the user compile all chunks, or only selected chunks.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: How to create methods programmatically - Dolphin 5.

Ian Bartholomew-19
In reply to this post by Randy Manning
Randy,

Just by the by ...

> crlf := Character cr asString,  Character lf asString.
> tab := Character tab asString.

You can make that a bit neater using the methods String class>>lineDelimiter
and String class>>tab

--
Ian

Use the Reply-To address to contact me.
Mail sent to the From address is ignored.


Reply | Threaded
Open this post in threaded view
|

Re: How to create methods programmatically - Dolphin 5.

Bill Schwab-2
Ian,

> > crlf := Character cr asString,  Character lf asString.
> > tab := Character tab asString.
>
> You can make that a bit neater using the methods String
class>>lineDelimiter
> and String class>>tab

Very true, and IMHO it's even cleaner using streams.  The tedious part is
getting started, which lead me to #scriptCodeGenerator in CodeGenerator's
IDE extension.  It is (by no means optimally) available on the class list
vs. the method list, but it gets the job done.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]