Skip to main content
Stack Overflow for Teams is now Stack Internal: See how we’re powering the human intelligence layer of enterprise AI. Read more >
Filter by
Sorted by
Tagged with
0 votes
2 answers
121 views

How can I define a variable that has shared access by instance methods of a Struct? I can use a global variable $tmp like this: Triple = Struct.new :x, :y, :z do def mul s $tmp.x = x * s $...
igouy's user avatar
  • 2,700
0 votes
1 answer
26 views

Say I have a JPanel with buttons (and other things) as components and I make an array of those components as such: JPanel panel = new JPanel(); JButton btn1 = new JButton(); JButton btn2 = new ...
Mr. Mutant's user avatar
0 votes
1 answer
99 views

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 ...
Phuc Dee's user avatar
0 votes
1 answer
28 views

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() ...
Sam's user avatar
  • 31
0 votes
3 answers
1k views

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 ...
chilliyayi's user avatar
1 vote
1 answer
378 views

I am passing a class as a parameter to a method and I need to create an instance of that class, something like public void setPiece(int i0, int j0, Class<Piece> pieceClass) { Piece p = ...
Daniel Barac's user avatar
-1 votes
3 answers
3k views

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__(...
user17625175's user avatar
1 vote
1 answer
1k views

I'm trying to create a function that triggers the class's init method and returns the instantiated class, but I'm not able to preserve the constructor and class types. I tried: class Test { ...
Slinidy's user avatar
  • 407
0 votes
1 answer
308 views

This is my code: class Category(): def __init__(self,category,balance=0,ledger=[]): self.category = category self.balance = balance self.ledger = ledger def ...
Emeric FOKOUONG TOUOLAC's user avatar
1 vote
1 answer
57 views

class Node: def __init__(self, value): self.data = value self.next = None class SinglyLinkedList: nodes = [] def __init__(self): self.head = None ...
Ruthvik Chandra Vanam's user avatar
0 votes
3 answers
3k views

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 ...
Charlotte O'Regan's user avatar
0 votes
2 answers
27 views

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 ...
Tom Connolly's user avatar
1 vote
1 answer
533 views

I am learning Ruby and have stumbled upon some code similar to the one below, which shows the difference between instance variables and class instance variables. I've tested it in my console and it ...
wawa's user avatar
  • 11
2 votes
1 answer
2k views

I don't understand the difference between struct and class equality check. Since both Struct and Class gets their #hash from Kernel but they seem to behave differently. I know that instance.hash ...
MorboRe''s user avatar
  • 161
0 votes
2 answers
303 views

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 < ...
Ashish Acharya's user avatar
0 votes
1 answer
249 views

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 ...
Routhinator's user avatar
  • 3,858
0 votes
0 answers
117 views

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 ...
Kawsar Haghshenas's user avatar
0 votes
0 answers
72 views

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), ...
superhero's user avatar
  • 305
0 votes
1 answer
196 views

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 ...
Gagan Ganapathy's user avatar
0 votes
1 answer
386 views

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 ...
theGreenCabbage's user avatar
0 votes
2 answers
213 views

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 ...
Boucherie's user avatar
  • 543
0 votes
0 answers
30 views

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(...
Mr. Suryaa Jha's user avatar
1 vote
1 answer
64 views

Ok, so I've read up on class variables, class instance variables and instance variables in Ruby. I found this explanation by Phrogz very illuminating. Now I'm trying to add a variable to my class ...
megahra's user avatar
  • 335
6 votes
1 answer
2k views

In module a.py def task(): print "task called" a = task class A: func = task # this show error unbound method #func = task.__call__ # if i replace with this work ...
Kallz's user avatar
  • 3,583
0 votes
1 answer
40 views

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 ...
user avatar
0 votes
1 answer
95 views

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 ...
Sean Chowdhury's user avatar
0 votes
1 answer
154 views

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 ...
skaz's user avatar
  • 22.8k
0 votes
1 answer
808 views

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 ...
Clayton Geist's user avatar
0 votes
2 answers
4k views

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(...
user avatar
10 votes
2 answers
3k views

According to Reek, creating a class variable is considered a 'code smell'. What is the explanation behind this?
Douglas's user avatar
  • 381
0 votes
1 answer
701 views

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 ...
Noble-Surfer's user avatar
  • 3,192
1 vote
1 answer
81 views

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 @...
Mary Rose Cook's user avatar
1 vote
2 answers
1k views

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 ...
Spyros's user avatar
  • 261
1 vote
1 answer
92 views

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 ...
jdno's user avatar
  • 4,384
-1 votes
1 answer
617 views

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",...
Subbi reddy dwarampudi's user avatar
5 votes
3 answers
4k views

I have created some Python classes to use as multivariate data structures, which are then used for various tasks. In some instances, I like to populate the classes with various value sets. The ...
Corey Petty's user avatar
4 votes
4 answers
4k views

Here is the link to my first question: Creating class instance from dictionary? So I am trying to create class instance from dictionary which holds keys that class has not. For example: class ...
Demyanov's user avatar
  • 921
2 votes
4 answers
498 views

class Event @event_list = {} attr_reader :name, :value def initialize(name, value) @name = name @value = value end def to_s "#{@value}" end class &...
Deepak's user avatar
  • 361
0 votes
2 answers
85 views

How is using studentName and studentAverage different in the class or in the constructor? public class StackOverFlowQ { String studentName; int studentAverage; public void ...
Snur Hamid's user avatar
1 vote
1 answer
56 views

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 ...
OldBoy's user avatar
  • 110
5 votes
3 answers
4k views

my idea is to create a community wiki for people that come from a java background because reading a lot of explanations, I couldn't comprehend anything until I actually tried a couple of things and ...
akostadinov's user avatar
4 votes
3 answers
203 views

I would like to understand initialization of class instances in various cases.. In JLS-7 Section 12.5, there was no mention of how and when final instance variables were initialized? Can some one ...
Pushparaj's user avatar
  • 1,059
1 vote
1 answer
194 views

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 ...
Alexander Popov's user avatar
1 vote
4 answers
914 views

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's user avatar
  • 2,373
3 votes
4 answers
662 views

I would like to deny creating instance variables in Ruby,to prevent unattended variables being created 'by mistake'. My class: class Test def initialize @a = 'Var A' end def make_new @...
meso_2600's user avatar
  • 2,146
1 vote
2 answers
443 views

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(...
Nicky Name's user avatar
0 votes
1 answer
73 views

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'; ...
learning php's user avatar
  • 1,274
1 vote
0 answers
151 views

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::...
shlajin's user avatar
  • 1,584
1 vote
4 answers
292 views

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 ...
Alexander Burke's user avatar
3 votes
1 answer
252 views

High-level picture of my program purpose: parse an XML file and save text into similar python objects problem: Every time I create a new python object and append it to a list, instead of creating a ...
Pswiss87's user avatar
  • 765