문제

I want to add an instance variable programatically to an existing class using Refactoring Browser:

| theClass className |
className := #MyClass.
theClass := (RBClass existingNamed: className)
                model: (RBNamespace new classNamed: className; yourself);
                yourself.
theClass addInstanceVariable: 'testIVar'

but the class is not modified with the new instance variable, what I am missing?

도움이 되었습니까?

해결책

You forgot to execute your refactoring. Try this

| model className theClass iVarName |
className := #MyClass.
iVarName := 'testIVar'.
model := RBNamespace new classNamed: className; yourself.
theClass := (RBClass existingNamed: className)
                model: model;
                yourself.
(RBAddInstanceVariableRefactoring 
        model: model
        variable: iVarName
        class: theClass) execute.

you may want to add authomatic accession methods (getter and setter) for your new instance variable

(RBCreateAccessorsForVariableRefactoring 
        model: model
        variable: iVarName
        class: theClass 
        classVariable: false) execute
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top