73 questions
0
votes
2
answers
121
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
99
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
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
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__(...
0
votes
1
answer
308
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 ...
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 ...
1
vote
1
answer
533
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 ...
0
votes
2
answers
303
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 < ...
0
votes
0
answers
117
views
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 ...
0
votes
1
answer
196
views
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 ...
0
votes
2
answers
213
views
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 ...
1
vote
1
answer
64
views
Ruby class variable scope issue
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 ...
0
votes
1
answer
40
views
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 ...
0
votes
1
answer
154
views
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 ...
0
votes
2
answers
4k
views
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(...
0
votes
1
answer
701
views
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 ...
1
vote
2
answers
1k
views
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 ...
-1
votes
1
answer
617
views
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",...
4
votes
4
answers
4k
views
Is there any way to get class instance attributes without creating class instance?
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 ...
0
votes
2
answers
85
views
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 ...
5
votes
3
answers
4k
views
ruby: class instance variables vs instance variables
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 ...
1
vote
1
answer
195
views
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 ...
3
votes
4
answers
662
views
How deny creating instance variables in Ruby
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
@...
0
votes
1
answer
73
views
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';
...
1
vote
4
answers
292
views
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 ...