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

Problem with class instances, Android

I am trying to make a game for android I have a bitmap and canvas instance in my main class. I have another instance of, lets say, renderer class. That renderer class is in the same package, but not the subclass of my main class. If i pass the…
Eric Cartman
  • 114
  • 10
0
votes
1 answer

Can't figure out how to create a "list" instance variable using class in Python

This is my code: class Category(): def __init__(self,category,balance=0,ledger=[]): self.category = category self.balance = balance self.ledger = ledger def check_funds(self,amt): if amt >…
0
votes
3 answers

Java how to call method in another class

Sorry for the basic question but I'm learning, new to programming. I am trying to call a method that is in another class but I'm unable to without passing in the required values for the constructor of Cypher class. Do i really need a new instance of…
0
votes
2 answers

Class Variables

Explain please, I can not understand. class Foo @a = 123 @@b = 123 end What are the advantages of variable objects-classes and the class variables? When should I use first, and in which the second?
0
votes
2 answers

@coffee_hour = Plan.find_by_event(:coffee_hour) ...Is it possible to link using a variable like this?

My Links table has five different events and I use partials because they are scattered around the page. As an examples, "coffee_hour", and "wine_time." Each event has a url and a time. In my controller I have: @coffee = Link.find_by(event:…
Tom Connolly
  • 674
  • 1
  • 5
  • 18
0
votes
2 answers

Create a new instance of parent's class variable for each child class

I have this parent class: class ListBase @@list = [] def self.list @@list end end I'm trying to create two child classes like so: class Child1 < ListBase end class Child2 < ListBase end I was under the impression that each of these…
0
votes
1 answer

Django Field Instances overriding each others arguments

I am testing and preparing a new Django package for using bleach with Text and Char fields in the Django ORM and with DRF. I've hit a bit of a roadblock with it however and it has made me take pause and wonder if I truly understand how a models…
Routhinator
  • 3,559
  • 4
  • 24
  • 35
0
votes
0 answers

Hierarchical abstraction in c++

I have following abstraction in my code: class A{}; class B: public A{}; class C: public B{}; Now when I declare an instance of class C every thing is OK. The problem is when I declare class C in a function (with new) an return it as a pointer. I…
0
votes
0 answers

how classes can inherit tk.frames when being called as a module in python

I am a tk newbie and am having trouble importing classes and having them inherit frames. If I stack all the code in one file it works. Something like (I found this on Github sorry for no attribution), imports... class Clock(Frame): def…
superhero
  • 185
  • 3
  • 16
0
votes
1 answer

Why are statically bound methods not involved in the CIR ( Class instance Record ) of the class while dynamically bound methods are?

I read in Sebesta that static bound methods do not need to be stored in the CIR but i cant figure out why. If it is not stored in the CIR, how does the compiler know which statically bound method is being referred to and where it is stored?
0
votes
1 answer

instance_variable_set is not setting the right variable in an instance

I have an API endpoint I'm testing using Ruby. I have 8 tests that look like the following: it "must rate limit on this api" do body = { .. } # Current limits assigned to this api endpoint are 5 requests every 5 minutes. # So this test…
0
votes
2 answers

Choosing a controller for a layout class instance variable in Rails

I have a DateTime class instance variable @current_year = DateTime.now.year, which I have set into a footer partial. This partial is rendered across several of my clientside pages (and across multiple controllers as <%= render 'layouts/page_footer'…
0
votes
0 answers

Can python class variable be used as both class and instance variable?

I am very confused after working with Django Framework and the model of Djano Framework class User(models.Model): first_name = models.CharField(max_length=20) last_name = models.CharField(max_length=20) email_address =…
0
votes
1 answer

Python: Can't search through list of class instance variables

I'm trying to create a chemistry GUI that shows various information about each element. I'm using a list of class instances to print out the information, but I continue to get a 'list' object has no attribute 'atomic_number'. This is the class I…
user7454726
0
votes
1 answer

Ruby: Nested Array behaving strangley as an Instance Variable

For our assignment, we were meant to create tic-tac-toe on a board of any size and accept an array as the input. I still am not fully grasping the attr_accessor module, and I'm pretty sure I used it incorrectly. class Board attr_accessor :grid …