class-variables

Static class variables in Python

Is it possible to have static class variables or methods in python? What syntax is required to do this? ...

How can Ruby's attr_accessor produce class variables or class instance variables instead of instance variables?

If I have a class with an attr_accessor, it defaults to creating an instance variable along with the corresponding getters and setters. But instead of creating an instance variable, is there a way to get it to create a class variable or a class instance variable instead? ...

In Ruby are there any related applications of the syntax: class << self ... end

class << self attr_accessor :n, :totalX, :totalY end The syntax above is used for defining class instance variables. But when I think about what syntax implies, it doesn't make any sense to me, so I'm wondering if this type of syntax is used for any other types of definitions. My point of confusion here is this: class << self The ap...

Is Rails shared-nothing or can separate requests access the same runtime variables?

PHP runs in a shared-nothing environment, which in this context means that every web request is run in a clean environment. You can not access another request's data except through a separate persistence layer (filesystem, database, etc.). What about Ruby on Rails? I just read a blog post stating that separate requests might access ...

Are "class var"s initialized to zero?

I know that, in Delphi, instance variables and global variables are initialized to zero (this has been asked here before). However, what about static variables (class var)? I would expect class vars to be initialized to zero, just like global variables. But I've seen too many new Delphi compiler features that were still half-baked to as...

java singleton pattern, should all variables be class variables?

If a class implements a singleton pattern, should all the variables be declared static? Is there any reason they shouldn't be declared static? Does it make a difference? ...

Java: Getting the properties of a class to construct a string representation

Let's say I have a class like this (and also further assume that all the private variables: public class Item { private String _id = null; private String _name = null; private String _description = null; ... } Now, if I want to build a toString() representation of this class, I would do something like this inside ...

What does class_getClassVariable() do?

If instance variables belong to an instance of a class, class variables would belong to an instance of a metaclass, I should think. But my experience with the Objective-C metaclass tells me that this is unlikely. I'm wondering what class_getClassVariable does as opposed to class_getInstanceVariable, and why there is not a class_setClass...

Ruby class variables

The ruby class-instance stuff is giving me a headache. I understand given this... class Foo @var = 'bar' end ...that @var is a variable on the created class's instance. But how do I create a sub-class overridable class variable? Here is an example of what I would do in Python: class Fish: var = 'fish' def v(self): return sel...

is there a hash equivalent to a custom 'class variables'? (ruby)

I used hash of hashes to store settings in my code. I wonder if I can have something like class variable that is the same for all instances of the class for my @profile hash. So both profiles below would have general profile variable equal to both of them. I want the solution to use hash. @profile = { "vB4Discussions" => { #profile...

referencing static methods from class variable...

I know it's wired to have such a case but somehow I have it: class foo #static method @staticmethod def test(): pass # class variable c = {'name' : <i want to reference test method here.>} What's the way to it? Just for the record: I believe this should be considered as python worst practices. Using static methods is ...

class variables and module inclusion, specifically in ActionController

I want to have some kind of single list that is initialized in a seperate module, then can be included in a controller and modified at the controller-class level, and accessed at the controller-instance level. I thought class variables would work here, but something strange is happening, they don't seem to be being initialized within my ...

How to make an IDisposable object a class variable?

I am working with Active Directory using C#. Instantiating the PrincipalContext object seems to be expensive, so I'd like to store one in a class variable. When using PrincipalContext as a local variable, I can use the convenient using syntax. When storing an IDisposable object in a static variable, how do I ensure the object is properl...

Assigning values : difference between properties and class variables ?

Hey guys, I noticed that I rarely use properties, due to the fact that I rarely need to access my object's variables outside my class ;) So I usually do : NSMutableArray *myArray; // not a property ! My question is : even if i don't declare myArray as a property, does iphone make a retain anyway if I do myArray = arrayPassedToMe;...

set static member pointer variables

I'm trying to set a static pointer variable in a class but I'm getting these errors for each variable I try to set. error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C2040: 'xscroll' : 'int' differs in levels of indirection from 'float *' error C2440: 'initializing' : cannot convert from '...

C++ : Initializing base class constant static variable with different value in derived class ?

I have a base class A with a constant static variable a. I need that instances of class B have a different value for the static variable a. How could this be achieved, preferably with static initialization ? class A { public: static const int a; }; const int A::a = 1; class B : public A { // ??? // How to set *a* to a valu...

Is it true that in most Object Oriented Programming Languages, an "i" in an instance method always refers first to local, and then to global, but never to the instance variable or class variable?

In the following code: <script type="text/javascript"> var i = 10; function Circle(radius) { this.r = radius; this.i = radius; } Circle.i = 123; Circle.prototype.area = function() { alert(i); } var c = new Circle(1); var a = c.area(); </script>...

Python Class Variables Question

I have some doubt about python's class variables. As my understanding, if I define a class variable, which is declared outside the __init__() function, this variable will create only once as a static variable in C++. This seems right for some python types, for instance, dict and list type, but for those base type, e.g. int,float, is no...

Python OOP and lists

Hi, I'm new to Python and it's OOP stuff and can't get it to work. Here's my code: class Tree: root = None; data = []; def __init__(self, equation): self.root = equation; def appendLeft(self, data): self.data.insert(0, data); def appendRight(self, data): self.data.append(data); def c...

Strategies for when to use properties and when to use internal variables on internal classes?

In almost all of my classes, I have a mixture of properties and internal class variables. I have always chosen one or the other by the rule "property if you need it externally, class variable if not". But there are many other issues which make me rethink this often, e.g.: at some point I want to use an internal variable from outside th...