Exemplo n.º 1
0
 def __getattr__(self, attr):
     if rubyapi.rb_respond_to(self.__ruby__, attr):
         return method_wrapper(self.__ruby__, attr)
     names = [attr + "?"]
     if attr.startswith("is"):
         names.append(attr[2:] + "?")
     if attr.endswith("p"):
         names.append(attr[:-1] + "?")
     if attr.startswith("force"):
         names.append(attr[5:] + "!")
     if attr.startswith("inplace"):
         names.append(attr[7:] + "!")
     if attr.startswith("in_place"):
         names.append(attr[8:] + "!")
     if attr.endswith("bang"):
         names.append(attr[:-4] + "!")
     for name in names:
         if name.startswith("_"):
             names.append(name[1:])
         if name.endswith("_"):
             names.append(name[:-1])
         if name.endswith("_?") or name.endswith("_!"):
             names.append(name[:-2])
     for name in names:
         if rubyapi.rb_respond_to(self.__ruby__, name):
             return method_wrapper(self.__ruby__, name)
     
     raise AttributeError("%r has no attribute %r" % (self, attr))
Exemplo n.º 2
0
 def __get__(self, obj, type = None):
     if rubyapi.rb_respond_to(obj.__ruby__, self.method_name):
         return method_wrapper(obj.__ruby__, self.method_name)
     else:
         raise AttributeError("ruby object %s does not respond to method :%s" % (inspect_value(obj.__ruby__), self.method_name))