methods

Python: How to override data attributes in method calls?

My question is how to use data attributes in a method but allow them to be overridden individually when calling the method. This example demonstrates how I tried to do it: class Class: def __init__(self): self.red = 1 self.blue = 2 self.yellow = 3 def calculate(self, red=self.red, blue=self.blue, yello...

A better way to stagger method calls/display 3 UIImageViews in delayed sequence

Hi all. I've managed to implement a solution to this problem, however the code just seems rather inefficient and actually, the delayed method calls are proving a little troublesome when they continue to fire if the user has navigated to another screen. Basically I want a thought bubble to appear from a character's head, but animated, so...

Separating the operation method from the result

I more than once saw code of the form: DiceThrower dt = new DiceThrower(); dt.throw(); //this is a void method int result = dt.getResult(); instead of DiceThrower dt = new DiceThrower(); int result = dt.throw(); My question is...why? Isn't it better to have the throw method returning the result? By not doing so, I could even incurr...

Writing a method in ruby that only acts on a collection of a Class

Guys, Is there a may to write an instance method that only operates on a collection of the class? So for example say I have something like this: class Foo def collection_method puts "I only work on a collection of Foo!" end end @foos = [] 5.times {@foos << Foo.new} @foo = Foo.new @foos.collection_method #=> I only w...

Passing methods as parameters on a deserialized form with no ClassType.

I'm effectively trying to deserialize a form. One of the objects on the serialized form has a method which takes a series of events as parameters. Now since I don't have the class type of the object when I'm deserializing, I have a method on the object doing the deserialization called AddMethod which is declared like this: procedure T...

What is wrong with this C# code?

public bool IsValid() { get { return (GetRuleViolations().Count() == 0); } } I'm getting this error: ; expected What is wrong? I'm following this tutorial: http://nerddinnerbook.s3.amazonaws.com/Part3.htm I'm not sure why they are using get. ...

Validating arguments to a method

Hello, I have a question on the best practice for validating arguments to a method when the arguments are contained within an object. For example, if you have: public class Student { public int getStudentId(); public String getStudentName(); public String getStudentSSN(); public double getStudentGpa(); public String...

is it better practice to return a complex object or use reference/out parameters?

I'm putting together a method which is supposed to evaluate the input and return true if all conditions are met or false if some test fails. I'd also like to have some sort of status message available to the caller if there's a failure. Designs I've come across include returning the bool and using an out (or ref) parameter for the messa...

PHP Static Method Using Private Class Functions/Variables

If I write a public static method in a class ie... public static function get_info($type){ switch($type){ case'title': self::get_title(); break; } } I have to write my get_title() function as public... public static function get_title(){ return 'Title'; } ...

NSObject may not respond to method.

Hi there. There are a few questions about this, but none of them helped me. I can't understand how things go about "calling one class method". I put a NSObject in Interface Builder. I subclassed it. I connected the object to a table view. I implemented the methods to populate the table view. I used an array, declared inside the object...

Is there any way to create default property implementations for C# interfaces

I like the technique of creating extension methods against interfaces to provide default functionality. One of the places it is very handy is in putting some meat on dummy classes for unit tests. For example, public interface IEmployee { IAddress Address { get; set; } IAddress GetAddress(); void SetAddress(IAddress addres...

How to name factory like methods?

I guess that most factory like methods start with create. But why are they called "create"? Why not "make", "produce", "build", "generate" or something else? Is it only a matter of taste? A convention? Or is there a special meaning in "create"? createURI(...) makeURI(...) produceURI(...) buildURI(...) generateURI(...) Which one would...

Calling Python instance methods in function decorators

Is there a clean way to have a decorator call an instance method on a class only at the time an instance of the class is instantiated? class C: def instance_method(self): print('Method called') def decorator(f): print('Locals in decorator %s ' % locals()) def wrap(f): print('Locals in wrapper ...

Visual Studio go to implementation

Hi everyone, On right mouse click on method call, we get context menu with options Go to definition and Go to implementation options among others. Why sometimes there is no Go to implementation option? Thanks a lot. ...

Chaining method PHP

<?php $sth = Framework::blah()->any_key['any_key_2']; ?> Hello, I want to get 'any_key' and 'any_key_2' in blah(), how I do that? ...

Android: Determine active input method from code

How do you determine which input method is currently active - A user can change the input method (soft keyboard) by long pressing on a text edit field - From code, how does one determine which input method the user has chosen ...

How to override JTextArea isEnabled() method

I want to override isEnabled() method in java.awt.Component and use it with a JTextArea. This is what I do. This code snippet is called inside the Jframe constructor. jTextArea1 = new javax.swing.JTextArea(){ @Override public boolean isEnabled(){ if(getForeground()== new Color(0, 0, 0)){ ret...

PHP: Get method's arguments?

In php I can check all available methods for an object like so: $methods = get_class_methods($object); But how can I see wich arguments have to be sent to these methods? Is there a function for this? ...

Can eclipse convert/refactor a method to a class?

This seems like it should be fairly straight-forward, but I can't see anything obvious. What I basically want to do it to point at a method and refactor->extract class. This would take the method in question to a new class with that method as top level public API. The refactoring would also drag any required methods and variables alon...

iPhone - Accessing superviews methods?

So essentially I'm inserting "startViewController" into "mainViewController" now of course I can access startViewControllers methods from mainViewController but I was wondering how to do the opposite? Occasionally startViewController will need to call something in mainViewController and I was just wondering how I do this? Thanks in adva...