Maybe worth noting that #storeString might not work so well with a Morph that's visible in the World... IIRC that ends up trying to store the whole World, because Morphs hang onto a reference to their current World.
It will work as long as there aren't cycles and it's not in the current world. In the menu of a workspace, there's an option to create references from dropped Morphs. I think the way I hustled around the problem was by dropping my handmade Morph into the workspace to get a reference, then detaching the Morph from the world with the halo (the workspace has a reference so the Morph doesn't meet the great garbage collector in the sky.) #storeString and #storeOn: are fun:) On Jun 9, 2012, at 2:37 PM, Chris Cunnington <[email protected]> wrote: > Well, I don't think you'd programmatically create a new class, because your > instance has to have been an instance of a class that already exists. Or else > you would not have an instance to begin with. > > Perhaps, you want a way to programatically reproduce an instance you've been > working with by hand in a Workspace. You have the instance. It's just right. > You want it to be programmatically reproducible at will. I'd use > Object>>storeString. > > x := (HelloWorld new) color: 'Black'. > > I've created a instance with an instvar. I send it storeString: > > x storeString > > and I get: > > '(HelloWorld basicNew instVarAt: 1 put: ''Black''; yourself)' > > It's a bit crufty to me. I remove the first and last quote and parentheses. > The double single quotes aren't great, so I remove them too. > > HelloWorld basicNew instVarAt: 1 put: 'Black'; yourself > > Print it, and get: > > a HelloWorld > > I'm not sure why it comes in some extra syntax. > That's my best guess at an answer to your question. YMMV. > > > Chris > > > > > On 2012-06-09, at 5:04 PM, Erich Groat wrote: > >> >> Hi all, >> >> I was wondering if there are any built-in facilities for taking a particular >> instance a class X, call it anX, and creating from it a class method that >> returns an identical instance of anX for future use. >> >> For example, say I'm futzing around in a workspace with an instance of a >> class called InteractiveWindowShape, tweaking things so that I have a nice >> window with all the colors and proportions and buttons I want, perhaps using >> Morphs to create the thing dynamically (so it's some kind of Morph object). >> In the course of this I get an instance of anInteractiveWindowShape that I >> am satisfied with, all the instance variables set just right. Let's call >> this object | idealShape |. It's just sitting there, rather vulnerably, in a >> workspace, the result of my using various screen tools over the last half >> hour. Now, I don't just want to save this object: I want to be able to >> create an identical one whenever I like. So what I want is a Class method, >> InteractiveWindowShapes class>>newIdealShape, that creates an instance >> exactly like idealShape. >> >> Is there a message I can send to this instance idealShape that would return >> a block of code that would act as a class method, which I could then call >> newIdealShape, and which would return an identical instance? >> >> I suspect such a general method might not exist, due to the potential >> hazards surrounding the deep copy problem; I also suspect I may not be >> imagining the best sort of solution to my problem. Is there a strategy for >> this? >> >> Thanks all! >> >> Erich >> _______________________________________________ >> Beginners mailing list >> [email protected] >> http://lists.squeakfoundation.org/mailman/listinfo/beginners > > _______________________________________________ > Beginners mailing list > [email protected] > http://lists.squeakfoundation.org/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list [email protected] http://lists.squeakfoundation.org/mailman/listinfo/beginners
