Task

The goal is to get the methods of an object, as names, values or both.

Some languages offer dynamic methods, which in general can only be inspected if a class' public API includes a way of listing them.

class Example {
    method foo { }
    method bar(arg) { say "bar(#{arg})" }
}
 
var obj = Example()
say obj.methods.keys.sort          #=> ["bar", "call", "foo", "new"]
 
var meth = obj.methods.item(:bar)  # `LazyMethod` representation for `obj.bar()`
meth(123)                          # calls obj.bar()