Questions tagged [class-method]

Methods that are called on a class instead of on an object.

Class methods are methods that are called on a class (compare this to class instance methods, or object methods). Its meaning may vary depending on the programming language: In some languages (e.g. C++, Java), class methods are synonymous with static methods (see section below), which are called with a known class name at compile-time. this cannot be used in static methods.

In some other languages (e.g. Smalltalk, Ruby, Objective-C), class methods are methods that are called on a class object, which can be computed at runtime, there being no difference between calling a method on a regular object or a class object; thus both instance and class methods are resolved dynamically, and there are no "static" methods. Notably, in these class methods, this refers to the class object.

Some languages have both. For example, in Python, one can create class methods and static methods using the classmethod and staticmethod decorators, respectively. The former has access to this (i.e. the instance object, conventionally known as self), while the latter does not.

904 questions
0
votes
1 answer

No class method for selector ... even though Xcode recognizes the method

I have 3 files: main.m, CGOAuth.h, CGOAuth.m (taken from https://github.com/guicocoa/cocoa-oauth) In main.m I call (in the main method): [GCOAuth URLRequestForPath:@"websites" HTTPMethod:@"GET" parameters:nil scheme:@"https" host:@"blah" …
user678392
  • 1,981
  • 3
  • 28
  • 50
0
votes
1 answer

Get Magento defined values for model "sales/order" status

I'm trying to perform some operations on an order if its status/state is "processing" (not sure if I should use status or state here .. any help on this would be great too). Running a ->getStatus() on a sales/order model tells me the value I'm…
Nick Rolando
  • 25,879
  • 13
  • 79
  • 119
0
votes
1 answer

calling a class method from scheduler.rake in ruby

Can you call a class method from a rakefile (scheduler.rake)? I am using the Heroku Scheduler add-on and wrote a task that calls a class method but I receive an error when I run 'heroku run rake auto_start_games' Connecting to database specified by…
Daniel Gaeta
  • 774
  • 2
  • 9
  • 22
0
votes
1 answer

ActiveRecord: class methods without scoping

I need to create a class method of my ActiveRecord. But that method is not meant to be a scope, so I'd like to prevent misusage of it like a scope. Is it possible to do?
Sergey Potapov
  • 3,819
  • 3
  • 27
  • 46
0
votes
1 answer

ZF2 using FilterProviderInterface to filter class method

I have a model class witch basically is the fields from a database table with getter and setters. class RealEstate extends BaseModel implements FilterProviderInterface { public $cityId; public $stateId; ... public $transferFields…
Exlord
  • 5,009
  • 4
  • 31
  • 51
0
votes
2 answers

switch-case statement as a method in a public class

Looking to implement a switch case statement method inside a class. I have a class that I'm writing to from a SQL select and sql datareader. Having trouble setting up the Status class which I pass in a string to it and it returns the corresponding…
Jt2ouan
  • 1,964
  • 9
  • 33
  • 55
0
votes
0 answers

Correct way to create class method with ARC - NSDictionary Leaks

I made a class method for read a plist file, and it works fine. I changed in ARC and now the class look like: + (NSDictionary *)readPlistDic:(NSString*)filePlist { NSString *documentsDirectoryPath =…
0
votes
0 answers

Python -- passing a populated list as a parameter for a constructor comes out as an empty list in the object

new to stackoverflow and new to Python. I appreciate all help given! I'm trying to call the constructor for a class and hand it a populated list. However, when the object is created the list is empty. The debugger shows the list is populated …
0
votes
7 answers

How to write an .add() method?

this is a homework problem, and I am having trouble understanding how I can create a .add() method in a class Distance. class Distance has two integer instance variables: private int feet; private int inches; It has a no argument constructor that…
Ishmael
  • 235
  • 3
  • 8
  • 17
0
votes
2 answers

iOS return bool value in block

I am trying to return a bool value from a class method I call that has a block in it. I get the error, Incompatible block pointer types sending.... How would I get around this? I just want to know if the class method I call completes with or without…
Jon Erickson
  • 1,876
  • 4
  • 30
  • 73
0
votes
4 answers

How to call class methods which are stored in a variable

If I want to call a class method (mailer method in rails), providing its name in a variable. How can I do that? For objects, we can use send, or we can use read_attribute to read some values…
Mohit Jain
  • 43,139
  • 57
  • 169
  • 274
0
votes
2 answers

How can I set conditional decorators on setUpClass in unittest?

I want to set a conditional decorator to the setUpClass in python's unitest. I have tried the following (without a condition for now, to demonstrate the point): import unittest class conditional_decorator(object): def __call__(self, func): …
Alex
  • 41,580
  • 88
  • 260
  • 469
0
votes
4 answers

How to acces Class methods?

I have a class method which takes an Array as the parameter +(void)classMethod:(NSArray*)array; A message is being sent to this method from an outside ViewController with the value of the array. [ViewController classMethod:ValueofArray] Now i…
newiosguy
  • 29
  • 1
  • 7
0
votes
2 answers

Why am I getting a "no visible @interface message for 'NSDecimalNumber' declares the selector" for my method?

I must be missing something simple here. Anyway, I started out by just making a regular function, NSDecimalNumber* aa(NSMutableString *string) {code} which I would then call by pressing a button like so: - (IBAction)parse:(id)sender…
0
votes
1 answer

Selectively allowing classes to use others' private class methods, or equivalent solution

In my project Bar, I have this class Foo, whose instances represent unique, named real-world objects. References to these instances are scattered under good care around the data structures in my project, but also, I have decided to make them…
Boris Stitnicky
  • 12,444
  • 5
  • 57
  • 74