instance-variables Questions

5

Solved

I'm unsure of the Python convention for type hinting instance variables - I've been doing them within the __init__ constructor arguments like seen here: class LoggedVar(Generic[T]): def __init__(s...

7

Solved

Here is some code: class Person def initialize(age) @age = age end def age @age end def age_difference_with(other_person) (self.age - other_person.age).abs end protected :age end Wh...
Argumentative asked 7/11, 2009 at 14:37

2

I wonder why Visual Studio is raising this warning: Access of shared member, constant member, enum member or nested type through an instance My code: Dim a As ApplicationDeployment = deploym...
Filiano asked 13/3, 2014 at 11:37

3

Solved

If an instance variable belongs to a class, can I access the instance variable (e.g. @hello) directly using the class instance? class Hello def method1 @hello = "pavan" end end h = Hello.new p...
Procurable asked 25/8, 2012 at 14:15

5

Solved

I have a Ruby class. I want to get an instance variable from an argument to a method in that class. I can do get all of the instance variables as an array: self.instance_variables However, I wan...
Lew asked 13/5, 2010 at 21:15

3

I am really confused about the __dict__ attribute. I have searched a lot but still I am not sure about the output. Could someone explain the use of this attribute from zero, in cases when it is us...

7

Is there any way to make instance variables "private"(C++ or Java definition) in ruby? In other words I want following code to result in an error. class Base def initialize() @x = 10 end end ...
Clone asked 25/1, 2010 at 11:34

4

Solved

When I am creating a new class, should I set all instance attributes in __init__, even if they are None and in fact later assigned values in class methods? See example below for the attribute...
Windpollinated asked 22/4, 2019 at 19:47

1

Below is my golang code. Each time validate method is called my compile method gets executed. I want to compile only once, not each time we call validate. 1) How to do it ? 2) My idea was to crea...
Ensoll asked 20/6, 2019 at 2:17

9

Solved

I'm implementing an object that is almost identical to a set, but requires an extra instance variable, so I am subclassing the built-in set object. What is the best way to make sure that the value ...
Coffer asked 28/4, 2009 at 15:5

6

Solved

What is the difference between a static and instance variable. The following sentence is what I cant get: In certain cases, only one copy of a particular variable should be shared by all object...
Foreshore asked 18/1, 2014 at 13:12

12

Solved

Is there a built-in method in Python to get an array of all a class' instance variables? For example, if I have this code: class hi: def __init__(self): self.ii = "foo" self.kk = "bar" Is the...
Grube asked 20/9, 2008 at 19:30

20

Solved

Let's say I have a Gift object with @name = "book" & @price = 15.95. What's the best way to convert that to the Hash {name: "book", price: 15.95} in Ruby, not Rails (although feel free to give ...
Perlite asked 17/2, 2011 at 14:56

8

Solved

I read When do Ruby instance variables get set? but I'm of two minds when to use class instance variables. Class variables are shared by all objects of a class, Instance variables belong to one obj...

3

Solved

I'm practicing lambda expressions in Java. I know local variables need to be final or effectively final according to the Oracle documentation for Java SE 16 Lambda Body : Any local variable, forma...
Opposite asked 12/4, 2021 at 20:15

4

Solved

I apologize in advance with what will probably be a fairly easy/quick answer based on scope, but I've looked everywhere and am surprised to not come up with an answer. I have created a class call...
Donley asked 9/9, 2012 at 1:46

3

Solved

I want to create an instance variable in a controller to be used in the view: foo = "bar" instance_variable_set("#{foo}", "cornholio") In the view, use @bar so that: @bar => "cornholio" Th...
Heterocyclic asked 8/3, 2012 at 2:18

7

Solved

My questions concern instance variables that are initialized in methods outside the class constructor. This is for Python. I'll first state what I understand: Classes may define a constructor,...
Concordant asked 14/7, 2016 at 14:44

3

Solved

I was given a link to the official oracle documentation: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html where it is said: Default Values It's not always nece...
Insectile asked 18/10, 2019 at 14:18

15

Solved

Is there any advantage for either approach? Example 1: class A { B b = new B(); } Example 2: class A { B b; A() { b = new B(); } }
Estray asked 3/1, 2010 at 6:53

2

Solved

I come from java background, so I am slightly confused here. Consider the code snippet below: class A(): def __init__(self, **kwargs): self.obj_var = "I am obj var" @classmethod def ...

4

Solved

I have just tried to lint some code with Pylint, and the last remaining error is R0902: too-many-instance-attributes (8/7) I understand the rationale behind limiting the number of instance attri...
Sarcophagus asked 26/6, 2014 at 15:27

5

Solved

I'm having confusion in calling a non-static method class A { void doThis() {} public static void main(String... arg) { A a1 = new A(); a1.doThis(); // method - 1 new A().doThis(); // method...
Uriah asked 17/1, 2017 at 11:49

4

Solved

Is it possible to define properties that are only available to the class they are defined in, and that class's subclasses? Stated another way, is there a way to define protected properties?
Paperback asked 24/11, 2010 at 7:9

6

Solved

I want to pass a default argument to an instance method using the value of an attribute of the instance: class C: def __init__(self, format): self.format = format def process(self, formatting=...
Jose asked 15/11, 2011 at 5:34

© 2022 - 2024 — McMap. All rights reserved.