methods

Class method does not invoke on iPhone

Hi, I wrote a small class containing 2 class methods for some calculations. I call those methods from another class. I have declared everything properly in both classes and Xcode does not give any warnings. Still, I checked with debugger and when I call method from this class it just doesn't invoke THis is declaration: +(double)Double...

Dynamic methods in a Module?

I've got a module called AB. Right now it looks something like this: module AB extend self def some_method(hash) .... end .... end We use it like this: AB.some_method(:thing=>:whatever,:etc=>'you get the idea'). There are about a half-dozen strings that the user has to pass in that I'd like to turn into dynam...

Java - How to Give method an array

I have a method like the following: public void launch(String cmd, String [] args, String workingDir) Inside this method I call ProcessBuilder. How can I call ProcessBuilder including an arbitrary number of args included in my args parameter? E.g., something like this: ProcessBuilder pb = new ProcessBuilder(cmd, args); I notice...

What are good tactics to do function extraction in Objective-C to create clean code?

In the book Clean Code the author recommends breaking large methods into small functions that do one specific thing. In languages like Java this translates to pretty, readable code. public static String renderPage(PageData pageData) { includeHeader(pageData); includeContent(pageData); includeFooter(pageData); return page...

Decorating a method

Hi In my Python app, I'm using events to communicate between different plugins. Now, instead of registering the methods to the events manually, I thought I might use decorators to do that for me. I would like to have it look like this: @events.listento('event.name') def myClassMethod(self, event) I have first tried to do it like thi...

How to judge whether a method has defined in a class?

class C1 unless method_defined? :hello # Certainly, it's not correct. I am asking to find something to do this work. def_method(:hello) do puts 'Hi Everyone' end end end So, how to judge whether a mehtod has defined or not? ...

ResourceManager override GetResourceFileName

Hi, I want to override a method in the System.Resources.ResourceManager class in mscorlib v4. I want to override the method GetResourceFileName like this; protected override string GetResourceFileName(CultureInfo culture) { string resourceFileName = base.GetResourceFileName(culture); return resourceFileName.Replace...

Class Definition properties or methods?

I have a class definition that I've seen other define properties that return collections of objects. Public Property GetAllAdults() as Adults ... End Property I made the argument that this should be a method in the class, because it doesn't define an attribute of the class, and could not be extended with parameters. Is/Are there reaso...

LD_PRELOAD for C++ class methods

I need to interpose on a method call in a C++ program (the class resides in a separate shared library). I thought I could use LD_PRELOAD, but i am not sure how this would work (i only found examples of C functions): is there a way to setup interposition for a single method without copying over any code from the interposed class implement...

Passing by reference and using ref

I looked at the similar questions and read some articles. THis article has some pictures which makes it clear. SomeObject so = new SomeObject(); somefunction(so); Console.write(so.x); // will print 1 SomeObject so1 = new SomeObject(); somefunctionByRef(so1); Console.write(so1.x); // will print 1 static void somefunction(SomeObject s...

Ruby - chaining methods and returning array

I have some methods for a class which return arrays like ["1", "3", "2", "6", "2"]. It is ok that these are string arrays, not numeric. I have another method that takes an array, and turns it into a single string like this 1 3 2 6 2. class Turn def initialize @rolls = 1 @dice = [] end def roll @roll = [] x = 5 - @dice.le...

symfony 1.4 : problem method isDeleted()

Hello, I want to test if an object is deleted after a calling to my function executeDelete in order to send to the user an error if the object is still in my database. if ($logement->isDeleted()) { $this->getUser()->setFlash('notice', 'Suppression du logement effectuée'); } else { $this->getUser()->setFlash('error', 'Erreur lors de...

VB.NET: Prepend a string to all strings in a list of strings. Is there an existing method that does this?

I have a list of strings. For each string in that list, I want to prepend another string. I wrote a method to do it, but I was wondering if there was something already in .NET I could use to do this. It seems like something that could be built in, but I was not able to find anything. Here is the method I wrote: Private Function Prepen...

What is the most appropriate sentinel method?

What is the most appropriate sentinel method? This breaks out of an infinite loop: infinite loop read in a value; if (value == Sentinel) then exit; process the value; This uses duplicate code: read in a value; while (value != Sentinel) process the value; read in a value; This uses a boolean variable i...

Child class as return type for a class method.

I have a C++ class which is meant to be inherited. All its children will inherit a method: class Record { public: RETTYPE* all(); }; class Child : public Record { int age; char *name; }; int main() { Child boo; Child boos* = boo->all(); // Pointer to array of Children return 0; }; How can I make a method retu...

Using gettext in CakePHP model validation

Hi! Is there any possibility to use the gettext functionallity within the CakePHP model validation array? Usually a programmer would do it like this: class Data extends AppModel { var $validate = array( 'title' => array( 'NichtLeer' => array( 'rule' => array('between', 4, 20), 'allowEmpty' => false, 'message' => _('B...

Problem in looping when using method in Java

I'm doing a simple program regarding methods. But I have one problem. Everything is already working except when looping. When I choose to loop again. The program skips on inputting the name. And proceeds directly to the year and section. Here's the code: public static void main(String[] args) { do{ System.out.println("Input info:")...

Cannot loop when using methods in java

Sorry for this guys, but I really am unlucky today. Please help, my problem a while ago was that I'm having problems while looping, and now it cannot loop at all. It won't let me enter the string to make it loop. Name, and year and section also outputs as null. I also tried using try catch but it doesn't seem to be picking up any errors...

Accessing a class's variable in Python

class Example(object): def the_example(self): itsProblem = "problem" theExample = Example() print(theExample.itsProblem) How do I access a class's variable? I've tried adding this definition: def return_itsProblem(self): return itsProblem Yet, that fails also. ...

Python : Allowing methods not specifically defined to be called ala __getattr__

Hi, I'm trying to write a Python class that has the ability to do the following: c = MyClass() a = c.A("a name for A") # Calls internally c.create("A", "a name for A") b = c.B("a name for B") # Calls internally c.create("B", "a name for B") A and B could be anything (well, they're defined in a database, but I don't want to explicitly...