[Newbies] Workspace-as-method?

C. David Shaffer cdshaffer at acm.org
Tue Jun 29 21:39:01 UTC 2010


Has anyone tried Workspace as method?  I'm not talking anything fancy,
just "accept" compiles the Workspace contents into a String in a method
which, when executed opens the workspace.  I'd like my workspaces
versioned with my code...maybe there's already a more refined version of
this.  Or maybe it's a bad idea?

Proof of concept attached.

David

-------------- next part --------------
Object subclass: #Workspaces
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'WorkspaceAsMethod'!

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

Workspaces class
	instanceVariableNames: ''!

!Workspaces class methodsFor: 'workspaces' stamp: 'cds 6/29/2010 17:36'!
first
	"self first"

	^Workspace new
		contents: 'We could even add nice menu item to specify the class and selector.';
		acceptAction: [:s | self compileWorkspaceContents: s asSelector: #'first' label: 'foo' ];
		openLabel: 'foo'! !


!Workspaces class methodsFor: 'utility' stamp: 'cds 6/29/2010 17:36'!
compileWorkspaceContents: aString asSelector: selector label: label

	| code |
	code :=
selector asString ,'
	"self ' , selector asString ,'"

	^Workspace new
		contents: ''', 
(aString copyReplaceAll: '''' with: '''''') , ''';
		acceptAction: [:s | self compileWorkspaceContents: s asSelector: #''' , 
selector asString , ''' label: ''' , label ,''' ];
		openLabel: ''' , label , ''''.
	self class compile: code classified: 'workspaces'! !


More information about the Beginners mailing list