11.2 Querying Methods and Properties
At runtime, we can query an object’s methods and properties to find out if the object supports a certain behavior. This is especially useful for behavior we add dynamically at runtime. We can add behavior not only to classes, but also to select instances of a class.
We can use MetaObjectProtocol’s
getMetaMethod
(MetaClass extends MetaObjectProtocol) to get a metamethod.
We can use
getStaticMetaMethod
if we’re looking for a static method.
To get a list of overloaded methods, we use the plural forms of these methods—
getMetaMethods
and
getStaticMetaMethods
.
Similarly, we can use
getMetaProperty
and
getStaticMetaProperty for a metaproperty. If we want simply to check for existence and not ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access