A class variable is any field declared with the static modifier.
347
votes
11answers
179k views
Static class variables in Python
Is it possible to have static class variables or methods in python? What syntax is required to do this?
16
votes
2answers
4k views
Difference between class variables and class instance variables?
Can anyone tell me about the difference between class variables and class instance variables?
13
votes
6answers
22k views
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 ...
6
votes
1answer
544 views
Is it thread safe to set Active Resource HTTP authentication on a per-user basis?
Active Resource can make use of HTTP authentication set at the class level. For instance:
class Resource < ActiveResource::Base
end
Resource.user = 'user'
Resource.password = 'password'
or
...
31
votes
3answers
12k views
What does @@variable mean in Ruby?
What are Ruby variables preceded with double at signs (@@)? My understanding of a variable preceded with an at sign is that it is an instance variable, like this in PHP:
PHP version
class Person {
...
26
votes
3answers
14k views
Create module variables in Ruby
Is there any way to create a variable in a module in Ruby that would behave similar to a class variable? What I mean by this is that it would be able to be accessed without initializing an instance of ...
13
votes
4answers
2k views
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 ...
4
votes
3answers
2k views
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 ...
16
votes
3answers
20k views
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 ...
9
votes
2answers
489 views
Why @@class_variable syntax should be avoided in Ruby?
I know that some say the @@class_var syntax should be avoid in Ruby and should use the @instance_var in the class' scope instead ...
def MyClass
@@bad_class_var # Should not do this.
...
8
votes
1answer
615 views
In Ruby, why after starting irb, foo.nil? says undefined error, and @foo.nil? gives “true”, and @@wah.nil? gives error again?
Same in Ruby 1.8.7 and 1.9.2:
$ irb
ruby-1.8.7-p302 > foo.nil?
NameError: undefined local variable or method `foo' for #<Object:0x3794c>
from (irb):1
ruby-1.8.7-p302 > @bar.nil?
...
2
votes
3answers
261 views
Python OOP and lists
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 ...
9
votes
2answers
7k views
python subclass access to class variable of parent
I was surprised to to learn that a class variable of a subclass can't access a class variable of the parent without specifically indicating the class name of the parent:
>>> class A(object):
...
10
votes
3answers
8k views
Where are static class variables stored in memory?
This is a follow-up question to How are static arrays stored in Java memory? .
So global variables in C/C++ are stored in the static data segment of memory. But what about static class variables in ...
18
votes
3answers
5k views
Constants or class variables in ruby?
I've been programming in Ruby for a few months now, and I'm wondering when it is appropriate to use constants over class variables and vice versa. (I'm working in Rails, thinking about constants in ...
4
votes
3answers
370 views
Difference Between Dot Notation and -> in Objective C
I'm trying to use as little memory as possible in my code. I've tried two ways of sending a custom class object to a method. I'm not sure if there is any difference between these two approaches. Say I ...
0
votes
4answers
510 views
Should I use class variables or class-instance variables for class static variables in Ruby?
class Something
@@variable = 'Class variable'
def give_me
@@variable
end
end
class OtherThing
@variable = 'Instance variable with an interface'
class << self
...
5
votes
2answers
321 views
Ruby class instance variable vs. class variable
I've read this thread When do Ruby instance variables get set? but i'm in two minds when to use class instance variables.
Class variables are shared by all objects of a class, Instance variables ...
2
votes
1answer
148 views
PHP performance: $this->variable versus local $variable (manipulating)
I had a section in a class that I decided to split into a new one.
When I had ported the code section into a new class I noticed it was considerably slower at executing one of the foreach loops.
I ...
2
votes
1answer
666 views
instance variable, class variable and the difference between them in ruby
I am having a hard time understanding instance variable, class variable and the difference between them in ruby... can someone explain them to me? I have done tons of Google searches, just can't ...
2
votes
5answers
2k views
Get a static property of an instance
If I have an instance in PHP, what's the easiest way to get to a static property ('class variable') of that instance ?
This
$classvars=get_class_vars(get_class($thing));
...
1
vote
2answers
611 views
Is Objective-C supported class variables?
I know it supported automatic variables, but what about class variables.
0
votes
1answer
103 views
Python: Accessing class variables from other class variables within the class - possible?
is it possible in python to address class variables from other class variables within the same class?
My problem is: I am trying to prepare some static code, that would look like this:
class ...
0
votes
3answers
182 views
Ruby and class variables in inherit class
class A
def set(v)
@@v = v
end
def put
puts @@v
end
end
class B < A
end
class C < A
end
B.new.set 'b'
B.new.put # => b
C.new.set 'c'
C.new.put # => c
B.new.put # => c
...
0
votes
1answer
1k views
Class variables, scope resolution operator and different versions of PHP
I tried the following code in codepad.org:
class test {
const TEST = 'testing 123';
function test () {
$testing = 'TEST';
echo self::$testing;
}
}
$class = new test;
And it returned ...