Le 28/06/2016 15:03, Nicolas Passerini a écrit :
Still, I think it would be nice to be able to save a method even when it does not compile.
I believe it would be better to be able to manipulate, inspect and edit properly virtual methods (MCMethodDefinition, RB-created methods) given that saving a method even if it does not compile is already possible, even if not made available in the GUI. Thierry
On Tue, Jun 28, 2016 at 2:52 PM, Peter Uhnák <i.uhnak@gmail.com <mailto:i.uhnak@gmail.com>> wrote:
Yeah I guess that's not such a bad idea, to have a TemplateClass that would contain just the template methods, so I don't need to worry about conflicting instance variables.
Peter
On Tue, Jun 28, 2016 at 2:08 PM, Ben Coman <btc@openinworld.com <mailto:btc@openinworld.com>> wrote:
On Tue, Jun 28, 2016 at 5:55 PM, Peter Uhnak <i.uhnak@gmail.com <mailto:i.uhnak@gmail.com>> wrote: > Hi, > > is it possible to accept a method without creating instance variable? > > E.g. > > ~~~~~~~~~~~~~~~~~~~~~~~~~~ > Object subclass: #MyObject > slots: { } > classVariables: { } > category: 'Category' > ~~~~~~~~~~~~~~~~~~~~~~~~~~ > > ~~~~~~~~~~~~~~~~~~~~~~~~~~ > MyObject>>addValue: aValue > container add: aValue > ~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Now normally when I would try to compile the method I would get the "Unknown variable 'container'" warning that will force me to either create temporary or instance variable; I would like to somehow ignore that, because the method will actually never get called. > > My objective is use this method as a template for code generation, so I would then take this method, apply some code transformation and compile it into different object. > > Of course I could do > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > MyObject>>addValueTemplate > ^ 'MyObject>>addValue: aValue > container add: aValue' > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > But then I would lose code highlighting, which is quite error-prone for more complex snippets. > > If you have a better approach, I am all ears. :) > > Thanks, > Peter
If you are only templating the method and not the whole class, why not add it as an instance variable MyObject? Or if MyObject is a real domain object with a few template methods, maybe put the templates on the class side and add a dummy class-instance-variable there.
cheers -ben