class-method Questions

3

I had following confusion. As far as I know the main difference between static and class keywords when declaring method is that the second one could be overridden in subclasses. The problem Howe...
Camarillo asked 14/5, 2015 at 9:34

2

I want to assert that one classmethod in a Python class calls another classmethod with a certain set of arguments. I would like the mocked classmethod to be "spec-ed", so it detects if it is called...
Perfervid asked 30/8, 2014 at 23:3

0

The implementation of abstractclassmethod abc.py in Python 3.4 looks like this: class abstractclassmethod(classmethod): __isabstractmethod__ = True def __init__(self, callable): callable.__is...
Marchpast asked 2/5, 2015 at 21:15

1

Solved

Based on what I read, class methods are largely the same as static methods with a few exceptions but have the advantage of providing a class pointer. As a result, is there really any reason to use...
Frippery asked 13/4, 2015 at 20:53

1

Solved

This scripts fails: import mock class MyClass(object): @classmethod def my_method(cls): print('my_method') def mocked_method(cls): print('I want this method to get called') with mock.patch...
Biochemistry asked 24/3, 2015 at 14:10

2

Solved

protocol NoteProtocol { var body: NSString? { get set } var createdAt: NSDate? { get set } var entityId: NSString? { get set } var modifiedAt: NSDate? { get set } var title: NSString? { get se...
Filmer asked 17/2, 2015 at 19:34

5

Solved

Pretty basic stuff but i am unable to troubleshoot where the problem is. In my project, i have a class named "TheFeedStore" with following two methods: - (BOOL)hasItemBeenRead:(RSSItem *)item { ....
Falciform asked 8/5, 2013 at 2:51

9

Solved

In Ruby, how do you call a class method from one of that class's instances? Say I have class Truck def self.default_make # Class method. "mac" end def initialize # Instance method. Truck.d...
Urea asked 27/3, 2010 at 1:48

5

Solved

Is there a way to do what classmethod does in Python in C#? That is, a static function that would get a Type object as an (implicit) parameter according to whichever subclass it's used from. An e...
Harmattan asked 13/1, 2010 at 17:35

1

Solved

In OCMockito, test doubles are implemented with NSProxy. A double standing in for an instance implements -respondsToSelector: as follows: - (BOOL)respondsToSelector:(SEL)aSelector { return [_mock...
Soulier asked 25/5, 2014 at 17:7

8

Solved

In Ruby, suppose I have a class Foo to allow me to catalogue my large collection of Foos. It's a fundamental law of nature that all Foos are green and spherical, so I have defined class methods as ...
Swivel asked 28/1, 2010 at 16:34

2

Solved

My Problem: I've created a series of nodes that each have a set of attribute objects associated with them. The attribute objects are initialized with descriptions and names for each attribute. I'd...
Sufficiency asked 28/3, 2014 at 3:2

2

Solved

Foo = Class.new Foo.instance_eval do def instance_bar "instance_bar" end end puts Foo.instance_bar #=> "instance_bar" puts Foo.new.instance_bar #=> undefined method ‘instance_bar’ My und...
Exum asked 23/5, 2009 at 2:22

2

Solved

I was doing some reading on the 'this' pointer, and I think I understand it more than I originally did, but I still need some clarification. So, by my understanding, if you have class Simple...
Cepheus asked 19/4, 2014 at 3:32

1

Solved

I am learning iOS programming and am confused by the following code regarding the use of keyword self. From my understanding, self is like Java's this. It refers to the current instance. When I wa...
Honewort asked 12/4, 2014 at 21:56

1

Solved

How should Rails named scopes be tested? Do you test the results returned from a scope, or that your query is configured correctly? If I have a User class with an .admins method like: class User ...
Harpsichord asked 7/4, 2014 at 2:29

7

I have difficulties understanding naming conventions of ARC. I have always coded with ARC, and I guess this is the reason. 1. Class methods What name should I choose for the following method? Wh...

3

Solved

In what sort of situation is the code: module M extend self def greet puts "hello" end end more beneficial to use over say something like: module M def self.greet puts "hello" end end ...
Bakeman asked 28/7, 2010 at 22:24

1

Solved

I'd like to be able to use __delitem__ with a class-level variable. My use case can be found here (the answer that uses _reg_funcs) but it basically involves a decorator class keeping a list of all...
Jailhouse asked 27/11, 2013 at 16:27

1

Solved

I want to monkey patch one single classmethod, keeping old functionality. Consider my code to get the idea. Here is my code (pretty synthetic example). #!/usr/bin/env python class A: @classmeth...
Prefecture asked 21/11, 2013 at 12:46

2

Solved

I'm new to the new query interface of ActiveRecord so I'm still figuring things out. I was hoping someone could explain the difference between using a scope in an ActiveRecord model and just usin...
Hostile asked 5/5, 2011 at 14:50

2

Solved

In the standard ember mixin example we add instance methods/properties: http://emberjs.com/api/classes/Ember.Mixin.html With reopenClass we can add class methods (static methods), giving us someth...
Testerman asked 20/5, 2013 at 23:6

2

Solved

While working on on open source project, I came across the following C function declaration and implementation: // FSNData.h NSString *stringForMimeType(MimeType type); @interface FSNData : NSObj...
Battalion asked 22/9, 2013 at 20:43

3

Solved

class A: def foo(self): print "foo()" getattr(A, foo) # True A.foo() # error getattr(A(), foo) # True A().foo() # prints "foo()" That being said, here is my problem: I wish to store test cas...
Octopod asked 28/8, 2013 at 21:14

1

Solved

sometimes I have need to write class with static methods, however with possibility to initialized it and keep state (object) sth like: class A: @classmethod def method(cls_or_self): # get refe...
Holography asked 6/8, 2013 at 11:18

© 2022 - 2024 — McMap. All rights reserved.