lib/pycall/pyobject_wrapper.rb in pycall-0.1.0.alpha.20170419a vs lib/pycall/pyobject_wrapper.rb in pycall-0.1.0.alpha.20170419b
- old
+ new
@@ -166,10 +166,18 @@
return res.to_ruby if LibPython.PyErr_Occurred().null?
raise PyError.fetch
end
def method_missing(name, *args, **kwargs)
- if PyCall.hasattr?(__pyobj__, name.to_s)
+ name_s = name.to_s
+ if name_s.end_with? '='
+ name = name_s[0..-2]
+ if PyCall.hasattr?(__pyobj__, name.to_s)
+ PyCall.setattr(__pyobj__, name, args.first)
+ else
+ raise NameError, "object has no attribute `#{name}'"
+ end
+ elsif PyCall.hasattr?(__pyobj__, name.to_s)
PyCall.getattr(__pyobj__, name)
else
super
end
end