73 questions
0
votes
2
answers
113
views
How to define a class instance variable in Ruby Struct subclass?
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
$...
0
votes
1
answer
25
views
Get the variable associated with a JPanel component from a component array
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 ...
0
votes
1
answer
92
views
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 ...
0
votes
1
answer
26
views
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() ...
0
votes
3
answers
1k
views
How to get the maximum value among the arguments of class objects in Python? [duplicate]
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 ...
1
vote
1
answer
327
views
Can I use a class instance as an argument for a generic in java?
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 = ...
-1
votes
3
answers
3k
views
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__(...
1
vote
1
answer
1k
views
instantiate typescript class instance with constructor parameters
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 {
...
0
votes
1
answer
306
views
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 ...
1
vote
1
answer
55
views
Why the list variable named nodes in the class is taking the output of the previous instance of the class?
class Node:
def __init__(self, value):
self.data = value
self.next = None
class SinglyLinkedList:
nodes = []
def __init__(self):
self.head = None
...
0
votes
3
answers
3k
views
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 ...
0
votes
2
answers
27
views
@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 ...
1
vote
1
answer
523
views
Does Ruby's define_method have special access to instance variables? [duplicate]
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 ...
2
votes
1
answer
2k
views
Why equality check for instance of Struct/Class are different?
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 ...
0
votes
2
answers
297
views
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 < ...