Questions tagged [class-instance-variables]

in ruby, where classes are objects, this means the instance variables of the class object itself

Here is an example:

class Test
  @ins1 = "gah"

  def initialize()
    @ins2 = "wtf?"
  end
end

@ins2 is an instance variable and @ins1 is a class instance variable. This might hopefully shed some more light over it: ruby: class instance variables vs instance variables

73 questions
0
votes
1 answer

Class instance variable not available to child class?

I want to leverage class methods on child classes in ruby, but those that rely on child instance variables are not working. I was told "don't use class variables! (@@)", so I'm not. How can I make class B do what I want, namely print out "1"? class…
skaz
  • 21,962
  • 20
  • 69
  • 98
0
votes
1 answer

Set Subclass Variables/Attributes from Within Base Class

Is it possible to dynamically create/set variables within a subclass within the base class across multiple subclasses without affecting the other subclasses? For example, take this code here: class Base: @classmethod def __init__(cls,v): …
0
votes
2 answers

Accessing Class variables from another class

How do you access an instance in an object and pass it to another 'main' object? I'm working with a parser for a file that parses different tags, INDI(individual), BIRT(event), FAMS(spouse), FAMC(children) Basically there are three classes: Person,…
user5549106
0
votes
1 answer

Python- how to query database by class

I have a Python project (I'm quite new to Python), and on one of the webpages, there is a drop-down box which should display a list of all of the projects whose 'status' fields are set to 'live'. It seems that a couple of particular objects are not…
Noble-Surfer
  • 3,052
  • 11
  • 73
  • 118
0
votes
2 answers

What is the difference between instance variables in a class or using them as parameters in a constructor in Java?

How is using studentName and studentAverage different in the class or in the constructor? public class StackOverFlowQ { String studentName; int studentAverage; public void StackOverFlowQ (String stedentName, int studentAverage){ …
0
votes
1 answer

anyway to access parent's properties who ware overwritten by child?

is there any work around to access the parents values that ware overwritten by child? parent::$prop: expect to be static. and the same with: self::$prop class base { public $name = 'base'; public function __construct() { …
learning php
  • 1,134
  • 2
  • 10
  • 14
0
votes
6 answers

Is the initialization with the pointers of class instance the only one in C++?

We all know, that the simplest way to define a new instance in C++ is the next: ClassName *obj = new ClassName(); But such a way is bad and more advanced people use smart pointers like: shared_ptr, unique_ptr etc... But if to look at their sources…
user2402179
0
votes
1 answer

Saving dict with nested class instances in Python 2.7

I'm trying to keep this as simple as possible. Basically I want the data to be saved to a file, and the retrieve it so that questor.py works and can "remember" everything it was ever taught on your machine. The original code is available on the web…
0
votes
1 answer

accessing an instantiated sealed class public member

i am trying to instatiate a public sealed class in my program, the thing is, ...as i am still fresh C# .net not-yet Developer , i find this issue a little difficult ... As for the problem in Question, you can skip straight to Program example, or…
LoneXcoder
  • 2,121
  • 6
  • 38
  • 76
0
votes
1 answer

Defining an accessor for the same class instance variable for a set of subclasses in Ruby

I have a superclass and a set of subclasses. In each subclass, I am defining a class instance variable that has the same name x. To create an accessor for one of these classes, I would just use in the subclass definition: class << self …
Sean Mackesey
  • 10,701
  • 11
  • 40
  • 66
0
votes
3 answers

What's the difference between defining class instance variable in a class and a method. Why?

Well, like the title shown, what's the difference between the two class instance variables below class Document @default_font = :Arial ... end And class Document def foo @default_font = :Arial end ... end Is there anyone can explain…
-1
votes
3 answers

getting field value from class instance in python

I don't understand how to get the value of a field instance from python class. I added what I need this code to do in get_person method. The output should be 3 or None. class Digit: def __init__(self, digit) self.digit = digit …
-1
votes
1 answer

Class instance variable is coming as `nil` in instance method

I assigned a class instance variable as an array. class Red @items = ["brinjal", "banana"] puts @items.inspect def test puts @items.inspect end end p = Red.new # => prints ["brinjal", "banana"] p.test # => prints nil If I access an…
1 2 3 4
5