Is there a cleaner way to determine if a method was called by a subclass?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Is there a cleaner way to determine if a method was called by a subclass?

Phil B
Let's say I have a class Foo with class method aMethod and a subclass
Bar, is there a way to determine whether or not aMethod is being called
by the parent class other than:
aMethod
        ^ self name = #Foo

i.e. I'd like to avoid referencing the class name if possible.  Is there
an introspective call I could use to accomplish this?


_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
Reply | Threaded
Open this post in threaded view
|

Re: Is there a cleaner way to determine if a method was called by a subclass?

Juan Vuletich-4
Hi Phil,

You can do:

cMethod
     ^thisContext methodClass == self class

This will answer true if run on the class that defines the method, and
false if inherited.

Cheers,
Juan Vuletich

On 5/1/2015 6:28 PM, Phil (list) wrote:

> Let's say I have a class Foo with class method aMethod and a subclass
> Bar, is there a way to determine whether or not aMethod is being called
> by the parent class other than:
> aMethod
> ^ self name = #Foo
>
> i.e. I'd like to avoid referencing the class name if possible.  Is there
> an introspective call I could use to accomplish this?
>
>
> _______________________________________________
> Cuis mailing list
> [hidden email]
> http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
>


_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
Reply | Threaded
Open this post in threaded view
|

Re: Is there a cleaner way to determine if a method was called by a subclass?

Phil B
On Fri, 2015-05-01 at 19:24 -0300, Juan Vuletich wrote:

> Hi Phil,
>
> You can do:
>
> cMethod
>      ^thisContext methodClass == self class
>
> This will answer true if run on the class that defines the method, and
> false if inherited.
>

Perfect!

> Cheers,
> Juan Vuletich

Thanks,
Phil


_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org