[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ismethod() work-around for 5.x
From: |
Andrew Janke |
Subject: |
Re: ismethod() work-around for 5.x |
Date: |
Tue, 8 Jun 2021 19:23:01 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 |
On 6/8/21 6:10 PM, Ray Daniel Zimmerman wrote:
> It appears that in Octave 5.x and earlier the ismethod() function does
> not find methods defined in a classdef. My current workaround is to move
> the methods into separate files in their own @class_name directory, but
> I’d rather not. So I was hoping to include my own ismethod()
> functionality in my package to support Octave 5.x.
>
> I would just look at the ismethod() source in Octave 6.x except that my
> code needs to be distributed under a BSD license.
>
> So, can anyone suggest an efficient approach for detecting whether a
> name is a method of an object … one that I could implement and include
> in my BSD licensed project?
>
> Thanks,
>
> Ray
Maybe you want the metaclass introspection mechanism?
klass = meta.class.fromName('someclass')
That'll get you a meta.class definition object (analagous to a
java.lang.Class object) for a given classdef class, with a MethodList
property that enumerates all the methods defined on it, including
inherited ones. Check if there's a method of that name in the list.
Won't be fast, but I think it'll be accurate, and easy to implement.
Maybe memoize it for a speedup.
Works for me in 4.4.1, so I think it'll work in 5.x too.
Cheers,
Andrew