Skip to content

Commit 20de59b

Browse files
committed
Add missing rich compare methods
1 parent 81c1c4a commit 20de59b

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

lib/pycall/pyobject_wrapper.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,19 @@ def respond_to_missing?(name, include_private)
4444
super
4545
end
4646

47-
def ==(other)
48-
case other
49-
when PyObjectWrapper
50-
LibPython::Helpers.compare(:==, __pyptr__, other.__pyptr__)
51-
else
52-
super
53-
end
47+
[:==, :!=, :<, :<=, :>, :>=].each do |op|
48+
class_eval("#{<<-"begin;"}\n#{<<-"end;"}", __FILE__, __LINE__+1)
49+
begin;
50+
def #{op}(other)
51+
case other
52+
when PyObjectWrapper
53+
LibPython::Helpers.compare(:#{op}, __pyptr__, other.__pyptr__)
54+
else
55+
other = Conversion.from_ruby(other)
56+
LibPython::Helpers.compare(:#{op}, __pyptr__, other)
57+
end
58+
end
59+
end;
5460
end
5561

5662
def [](*key)

spec/pycall/pyobject_wrapper_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,30 @@ module PyCall
9090
end
9191
end
9292

93+
describe '#==' do
94+
pending
95+
end
96+
97+
describe '#!=' do
98+
pending
99+
end
100+
101+
describe '#<' do
102+
pending
103+
end
104+
105+
describe '#<=' do
106+
pending
107+
end
108+
109+
describe '#>' do
110+
pending
111+
end
112+
113+
describe '#>=' do
114+
pending
115+
end
116+
93117
describe '#[]' do
94118
pending
95119
end

0 commit comments

Comments
 (0)