Questions tagged [instance-method]

30 questions
1
vote
0 answers

Does Class method return any thing

hi everyone I know the difference between class method and instance method. My question is "when a class methods returns any value/anything, that returned value can be hold in variable/any object ?" because in my code class method is returning the…
Nasir
  • 1,617
  • 2
  • 19
  • 34
1
vote
2 answers

Undefined method in some cases for instance method defined in a subclass

After much trial-and-error and searching for an existing answer, there seems to be a fundamental misunderstanding I'm having and would love some clarification and/or direction. Note in advance: I'm using multiple table inheritance and have good…
uhezay
  • 341
  • 1
  • 2
  • 11
1
vote
1 answer

How can I get instance method parameters?

I'm trying to retrieve the parameters for a couple instance methods. The idiomatic Ruby way to do this is like so: class A def test(id) puts id end end A.instance_method(:test).parameters #=> [[:req, :id]] This approach works most of the…
fbonetti
  • 6,652
  • 3
  • 34
  • 32
1
vote
1 answer

Cocoa-Touch. What Exactly is the Difference Between These NSMutableData Methods?

One thing I'm a bit unclear on is the difference between these NSMutableArray Methods: // Class Method Style NSMutableData *myMutableDataInstance = [NSMutableData dataWithLength:WholeLottaData]; and // Instance Method Style NSMutableData…
dugla
  • 12,774
  • 26
  • 88
  • 136
0
votes
4 answers

Objective C Instance Method Help *Beginner*

Can you guys help me understand a concept real quick, I'm having trouble understanding the conversion from C to objective-C: If I had a particular instance method that look like this: -(void)addOwnerNamesObject:(NSString *)n; { // ownerNames…
HashHazard
  • 561
  • 4
  • 14
0
votes
1 answer

How do I define in the model a class method, not an instance one?

I want to be able to call Activity.pull_latest from a controller, but if I do class Activity < ActiveRecord::Base def pull_latest [...] I have to call it Activity.new.pull_latest. How do I define in the model a class method, not an instance one?
Marius Butuc
  • 17,781
  • 22
  • 77
  • 111
0
votes
0 answers

How to overcome this error "TypeError: unsupported operand type(s) for -: 'float' and 'instancemethod'"

I'm working with pandas and i just came across this error, So basically i concated several dataframes to make one and i took the 'mean' and 'std' of each column using the following command df = pd.concat(df_all) df =…
user10337478
0
votes
1 answer

How can I dynamically add/extend methods from a Class?

I'm using a Ruby Component inside an Audio Application Environment. This Ruby Component is represented by an instance of a RubyEdit class. This provide the interface between my Ruby code and the Environment. For example if I write self it outputs…
markzzz
  • 47,390
  • 120
  • 299
  • 507
0
votes
2 answers

Why can a factory method call an instance method?

As we all know, factory methods can't call instance methods. Why does the code below work? // .m file implementation DemoClass // custom instance init method - (instancetype)initWithDate:(NSDate *)date { if (self = [super init]) { …
Jack.Ma
  • 1
  • 1
0
votes
0 answers

Swift: initialising an instance method using class initialiser and 'let'. Is it correct?

With this simplified Unit class, I have an unset method called myMethod which is initialised when a new instance is created. typealias Converter = (input: Double) -> Double class Unit { let name: String let myMethod: Converter …
Gabriel
  • 27
  • 6
0
votes
1 answer

rails instance methods not working on relation

I feel like I am making a syntax error. I am trying to define an instance method in the model, that then gets called with an instance receiver. but the output is nilClass. What am I doing wrong? model class Park < ActiveRecord::Base has_many…
ahnbizcad
  • 10,491
  • 9
  • 59
  • 85
0
votes
0 answers

label.text not changing after instance method called in appDelegate. Why would this be?

I have a label in a view that updates the text when a void is called. I am calling this void from my app Delegate. Using break points I can see the instance method is working and the line that changes the labels text is being call. Only the text is…
user2601032
  • 67
  • 1
  • 7
0
votes
3 answers

How can I make this conditional riddled instance method more Ruby idiomatic?

def short_remaining_time difference = Time.diff(Time.now, created_at + 7.days, '%d - %H - %N') # To display the short remaining time in an auction listing. if difference[:day] == 0 and difference[:hour] >= 1 …
sergserg
  • 21,716
  • 41
  • 129
  • 182
0
votes
1 answer

How can OOP be implemented to call an instance method from one class to be stored in an array in another instance method in a different class?

To further develop an understanding of my question: I have a problem that I am working on in my Java textbook where it asks me to write a class named GroceryList that represents a list of items to buy from the market, and also another class named…
user2014599
-2
votes
3 answers

Random Int as Parameter Java

I am making a very simple Java application called "Amazing Pets." It involves Humans and their Pets (Cats or Dogs). In this case, we are dealing with the Dogs. How do I create an instance method for Humans (called makeDogMakeNoise) which calls the…
theenigma
  • 431
  • 1
  • 6
  • 6
1
2