Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
194 posts
|
Hi guys!
How can I add method (I have RBMethod) to a class in code? I'm asking because existing method addMethod: in RBAbstractClass isn't working. Here is a piece of my code: method:= RBMethod for: class source: ('^ ', newName asString) selector: newName asSymbol. class addMethod: getter. Best Mark |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
194 posts
|
P.S. obviously, my method is added to newMethods var, but it is not disblayed in my class. 2014-07-17 15:53 GMT+02:00 Mark Rizun <[hidden email]>: Hi guys! ... [show rest of quote] |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
78 posts
|
I don't know what RBMethod is, but you can do aClass compile: source. For example: Array compile: 'newMethod ^ 1' I don't know if it answers your question. Regards 2014-07-17 15:57 GMT+02:00 Mark Rizun <[hidden email]>:
... [show rest of quote] |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
11 posts
|
I think you have to add a "RGMethodDefinition" or a "CompiledMethod". Obviously in a class methodDict the values are CompiledMethod. Regards, De: "Sebastian Tleye" <[hidden email]> ... [show rest of quote] |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
194 posts
|
Thank you all. Problem is solved, I just used RBAddMethodRefactoring. Mark 2014-07-17 16:07 GMT+02:00 Baptiste Quide <[hidden email]>:
... [show rest of quote] |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
1675 posts
|
No. Adding a method is not a refactoring. You should use RBAddMethodChange: | model |model := RBNamespace new. (model classNamed: #Model) compile: 'asString ^ String empty' classified: #(accessing). model changes execute. Hernán 2014-07-17 11:08 GMT-03:00 Mark Rizun <[hidden email]>:
... [show rest of quote] |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
194 posts
|
Thanks Hernan 17 лип. 2014 18:29, користувач "Hernán Morales Durand" <[hidden email]> написав:
... [show rest of quote] |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
6187 posts
|
Hi, Model compile: ‘method ...’ classified: ‘accessing’.
Esteban On 17 Jul 2014, at 18:52, Mark Rizun <[hidden email]> wrote:
... [show rest of quote] |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
1675 posts
|
Yes you need it because when doing code generation you cannot always assume target class is present. Besides using RB you can confirm through the NautilusRefactoring which is useful for massive changes: Cheers,| model | model := RBNamespace new. (model classNamed: #Model) compile: 'asString ^ String empty' classified: #(accessing). (ChangesBrowser changes: model changes changes) openWithSpec Hernán 2014-07-17 13:55 GMT-03:00 Esteban Lorenzano <[hidden email]>:
... [show rest of quote] |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
5447 posts
|
cheers -ben Hernán Morales Durand wrote:
... [show rest of quote]
|
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
2446 posts
|
But wait. What happens here is that we are mixing concepts. 1) On one side, there is Pharo's class model (the one we program with) => classes, metaclasses, methods. Let's call them the *real* classes and methods. So if you want to add a method to your *real* class, you usually have to
- compile a method - add it to the method dictionary of the class There are some helper methods that do all the work in one step, as mentioned by Esteban: myClass compile: someCode classified: aProtocolName. That, is what happens when you use the browser (Nautilus in our case). 2) On the other side, there is the Refactoring browser framework (that is, all classes prefixed as RB (except the AST nodes now)). The refactoring browser implements refactorings (renames of classes and methods, pushing up/down instance variables in a hierarchy, extracting methods into classes). Of course, to apply these refactoring it uses the model and API's provided by 1). But it's a completely different monster.
That means, adding a RBMethod in a RBClass does not mean that you are adding a *real* method into a *real* class. That will not happen unless that change is inside a refactoring and you apply the refactoring.
On Fri, Jul 18, 2014 at 3:43 AM, Ben Coman <[hidden email]> wrote:
... [show rest of quote] |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
6187 posts
|
also you will still have an error if using the RBNamespace instead the direct method invocation, if class does not exist.
So… I stand with my opinion :) If you want to control existence, you could do something like this: #Model asClassIfPresent: [ :class | class compile: 'asString ^ String empty' classified: #accessing ] Esteban On 18 Jul 2014, at 11:19, Guillermo Polito <[hidden email]> wrote:
... [show rest of quote] |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
194 posts
|
Thank you very much guys. I think, now I can understand what is going on with method adding:) Best, Mark 2014-07-18 12:09 GMT+02:00 Esteban Lorenzano <[hidden email]>:
... [show rest of quote] |
Free forum by Nabble | Edit this page |