How to call Python constructors, callables, and keyword arguments
masterPyCall maps Python syntax to idiomatic Ruby syntax:
- Constructors: Python
classname(x, y)becomes Rubyclassname.new(x, y). - Callable Objects: Python
obj(x, y)becomes Rubyobj.(x, y). - Keyword Arguments: Python
func(x=1, y=2)becomes Rubyfunc(x: 1, y: 2). - Attributes/Methods: Python
obj.meth(x, y=1)becomes Rubyobj.meth(x, y: 1).
Note: Because methods are mapped to Ruby instance methods, you cannot access a callable attribute directly via dot notation. To get the actual callable object, use PyCall.getattr(obj, :meth).
# Constructor
obj = MyClass.new(arg1)
# Callable object
obj.(arg1)
# Keyword arguments
obj.method(key: value)
# Getting a callable attribute (instead of obj.meth)
meth = PyCall.getattr(obj, :meth)