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
1
vote
1 answer

Why can't a class instance variable be accessed in a singleton-class definition in Ruby?

class MyClass @my_class_instance_variable = "here" p @my_class_instance_variable # => "here" class << self p @my_class_instance_variable # => nil end end class MyClass p @my_class_instance_variable # => "here" end Why does the…
Mary Rose Cook
  • 365
  • 4
  • 9
1
vote
2 answers

C# display image in WPF from a custom class other than MainWindow : Window

Hello I have a simple WPF window and I want to load and display a logo image on specific "Image" item. The following code works perfectly and I can display the logo. namespace WPFexample { public partial class MainWindow : Window { …
Spyros
  • 261
  • 2
  • 14
1
vote
1 answer

How to declare Class Instance Variable in inherited class automatically

I am using Class Inheritance Variables in Ruby to keep track of the number of instances I've created so far. To keep my code DRY, I implemented most of the logic in a base class that all my other classes inherit from. class Entity …
jdno
  • 4,104
  • 1
  • 22
  • 27
1
vote
1 answer

class instance variables proper usage

class variable works like this: class Hello @@x = 0 def self.counter @@x end def initialize @@x += 1 end end Hello.new Hello.new Hello.new p Hello.counter #=> 3 but class instance variable doesn't: class Goodbye @x = 0 …
OldBoy
  • 110
  • 1
  • 8
1
vote
1 answer

How to declare a class instance variable in Ruby?

I need a class variable which does not get inherited, so I decided to use a class instance variable. Currently I have this code: class A def self.symbols history_symbols end private def self.history_tables @@history_tables ||=…
1
vote
4 answers

Relation between class instance and static methods

Is there any particular relation between class instance (e.g variables that declared by static/final) and static methods(e.g class methods) ? I hop you understand what i mean.
Sajad
  • 2,273
  • 11
  • 49
  • 92
1
vote
2 answers

How can I pass an object instance in a method call in C#?

I have a class Club which has a list _list as an argument, while 'Player' is another class ... I have this method for adding the club members, thas is implemented this way: public void AddPlayer(Player p) { if(_list.Contains( p)) throw…
1
vote
0 answers

Ruby/Rails: trying to invent an inherited resource gem. Class instance variable in mixin

I want to DRY my views and controllers from a lot of similar code. I want to do it by myself in educational purpose, I know about the InheritedResourse gem. So far I wrote: class Admin::ResourcesController < Admin::AdminBaseController …
shlajin
  • 1,416
  • 10
  • 23
1
vote
4 answers

Why are my instance variables not existing across methods of the same class in ruby?

I am doing the ruby koans and I am on the DiceSet project. I've made the DiceSet class but my instance variables don't seem to persist with the instance like I thought they would. My code is class DiceSet attr_reader :values @values = [] …
0
votes
0 answers

Update different dataframes in imported module from inside a class instance, depending on parameters sent to class instance

I believe my problem is adequately described in the picture: In the first function, I assign one of two imported dataframes as params to be sent to the class instance. In the class instance, these params become dataframes contained in local…
0
votes
0 answers

Weird Python shared class variables between obejcts

class XMLData: fileName = '' tagName = [] tagDic = {} def __init__(self, fileName): self.fileName = fileName self.myTree = ET.parse(fileName) self.myRoot = self.myTree.getroot() self.__setTagsWithUri() more methods in…
0
votes
1 answer

Class Inheritance python require fill child class name

it might be a silly question since I'm new to Python. However, I hope someone can explain this because I try to find lots of resource but still hardly understand the mechanism behind. So I create a Parent Class and a Child Class. Parent Class have…
0
votes
1 answer

Singleton module or class methods + class instance variables for singleton-like behaviour in Ruby?

I need class that has singleton behaviour. What's the difference between using the Singleton module... require 'singleton' class X include Singleton def set_x(x) @x = x end def test puts @x …
AJM
  • 655
  • 1
  • 9
  • 19
0
votes
1 answer

aiohttp instance variable values shared by different users?

I am testing an aiohttp app with web.run. I instantiate an imported class just after the import declaration and the a value of this instance is changed by data channel( for instance.changevalue() function). It works well for a single user. But when…
Sam
  • 21
  • 5
0
votes
3 answers

How to get the maximum value among the arguments of class objects in Python?

I have sample class and instances: class A: def __init__(self, num) #instances a = A(2) b = A(4) c = A(5) d = A(7) In another class (class B) within a method, I have to get the highest value among the arguments 2,4,5,7 because I need it for a…