Skip to content

Commit 64db7bf

Browse files
committed
Update callable attribute explanation in README.md
1 parent c20aaae commit 64db7bf

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,20 @@ boolean, string, arrays, and hashes.
6666

6767
Pycall.rb maps the callable attribute of an object to the instance method of the corresponding wrapper object. So, we can write a Python expression `obj.meth(x, y, z=1)` as `obj.meth(x, y, z: 1)` in Ruby. This mapping allows us to call these attributes naturally as Ruby's manner.
6868

69-
But, unfortunately, this mapping prohibits us to get the callable attributes. We need to write `PyCall.getattr(obj, :meth)` in Ruby to get `obj.meth` object while we can write `obj.meth` in Python.
69+
In Python, you can get a method object (callable attribute) or call it:
70+
71+
```python
72+
obj.meth # get the method object (callable attribute)
73+
obj.meth() # call the method
74+
```
75+
76+
In PyCall.rb, `obj.meth` always calls the method (equivalent to `obj.meth()` in Python).
77+
To get the method object itself (not call it), use `PyCall.getattr`:
78+
79+
```ruby
80+
obj.meth # calls Python's obj.meth()
81+
PyCall.getattr(obj, :meth) # gets Python's obj.meth (the method object)
82+
```
7083

7184
### Specifying the Python version
7285

0 commit comments

Comments
 (0)