class-method

    1热度

    2回答

    ,如果有任何存储器/性能的缺点,或者只是在一般缺点我想知道,在使用类方法,如: + (void)myClassMethod:(NSString *)param { // much to be done... } 或 + (NSArray*)myClassMethod:(NSString *)param { // much to be done... return [NSArra

    6热度

    5回答

    有没有办法做什么classmethod在Python在Python中做的? 也就是说,一个静态函数将根据使用的任何子类将Type对象作为(隐式)参数。 的我想要的一个例子,大约是 class Base: @classmethod def get(cls, id): print "Would instantiate a new %r with ID %d."%(cls

    3热度

    1回答

    我正在研究一个将CouchDB支持添加到Flask的Flask扩展。为了方便起见,我分类了couchdb.mapping.Document,所以store和load方法可以使用当前的线程本地数据库。现在,我的代码如下所示: class Document(mapping.Document): # rest of the methods omitted for brevity @c

    0热度

    2回答

    我有多个类,我想向其发送相同的消息。更清晰: 我想发送 doX:withClass:具有相同的参数给多个类。也许代码会更清楚: + (void)doX:(NSString *)blah { [Utility doX:blah withClass:[Foo class]]; [Utility doX:blah withClass:[Bar class]]; [Utili

    14热度

    2回答

    我被卡住了。我试图动态地定义一个类方法,我无法将我的头围绕在ruby元类模型上。考虑以下类: class Example def self.meta; (class << self; self; end); end def self.class_instance; self; end end Example.class_instance.class # => Cla

    5热度

    9回答

    #! /usr/bin/env python import os import stat import sys class chkup: def set(file): filepermission = os.stat(file) user_read() user_write() user_exec()

    12热度

    3回答

    我有一个类定义了一个常量。然后我定义了一个类方法来访问那个类的常量。这工作正常。一个例子: #! /usr/bin/env ruby class NonInstantiableClass Const = "hello, world!" class << self def shout_my_constant puts Const.upcase

    282热度

    9回答

    调用类的方法在Ruby中,你怎么骂从该类的实例中的一个类的方法?假设我有 class Truck def self.default_make # Class method. "mac" end def initialize # Instance method. Truck.default_make # gets the def

    4热度

    2回答

    在UIControlEventTouchDown之类的任何事件之后,如何使UIButton在类MyClass上执行我的班级方法+doSomething:(id)sender?我可以像我一样使用-addTarget:action:forControlEvents:作为实例方法吗? 在此先感谢。

    7热度

    2回答

    我很难理解classmethod对象在Python中的工作方式,特别是在metaclass和__new__中。在我的特殊情况下,我想获得一个classmethod成员的名字,当我遍历__new__给出的members。 对于常规方法,名称只存储在__name__属性中,但对于类方法,显然没有这样的属性。我什至不知道如何调用类方法,因为也没有__call__属性。 有人可以向我解释一个classme