[Newbies] adding methods to a class at runtime

David Mitchell david.mitchell at gmail.com
Mon Aug 13 15:37:07 UTC 2007


Sure, but Smalltalkers wouldn't wait for the first run of the program
to create the accessors. And, unlike Ruby, once you ran the create
accessor code, the accessors would be part of the code that goes under
version control.

This is one of the big differences between Ruby and Smalltalk. In
Smalltalk, there isn't much distinction between runtime and edit time.
Technically, there isn't any distinction. Even when you are editing
code, you are in some sense running the eventual application.

In fact, Smalltalkers often keep their application running as they make changes.

Take a look at:
CreateAccessorsForVariableRefactoring

Which you can invoke by right clicking on a class in the OmniBrowser
and choosing "accessors for instvar".

No reason you couldn't invoke such code at "runtime".

On 8/13/07, Mark Volkmann <mark at ociweb.com> wrote:
> Is it possible to write code that adds methods to a class at runtime. In
> particular I'm thinking about something like attr_accessor in Ruby which
> adds get and set methods for instance variables so you don't have to write
> them.
>
> Thanks to everybody who has answered my questions so far!
>
> ---
> Mark Volkmann
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
>


More information about the Beginners mailing list