methods

Calls block once for each element of an array, passing that element as a parameter

Hello, I have some difficulties for using Ruby block, passing in a method. As in the following case, I would like to display each element of @array, from Box instance (using .each method): class Box def initialize @array = [:foo, :bar] end def each(&block) # well, hm.. end end a = Box.new a.each { |element| puts eleme...

Objective-C Class Question?

Hey, My head is about to explode with this logic, can anyone help? Class A #imports Class B. Class A calls Method A in Class B. This works great Class B wants to send a response back to Class A from another method that is called from Method A. If you #import Class A from Class B, it is in effect an infinite loop and the whole thing cr...

Accessing Class Variables from a List in a nice way in Python

Suppose I have a list X = [a, b, c] where a, b, c are instances of the same class C. Now, all these instances a,b,c, have a variable called v, a.v, b.v, c.v ... I simply want a list Y = [a.v, b.v, c.v] Is there a nice command to do this? The best way I can think of is: Y = [] for i in X Y.append(i.v) But it doesn't seem ...

Can fields of the class and arguments of the method interfere?

I have a class with a fields called "a". In the class I have a method and in the list of arguments of this method I also have "a". So, which "a" I will see inside of the method? Will it be the field or it will be the argument of the method? public class myClass { private String a; // Method which sets the value of the field "a". ...

in ASP.Net, are long running static operations a bottleneck?

If a long running operation is defined in a frequently called static method, is it a bottleneck for other threads in an ASP.Net application trying to call the same method? Does that only apply to methods with the "Synchronized" attribute>? I've searched and can't seem to find a definitive answer. ...

Why can't I pass self as a named argument to an instance method in Python?

This works: >>> def bar(x, y): ... print x, y ... >>> bar(y=3, x=1) 1 3 And this works: >>> class Foo(object): ... def bar(self, x, y): ... print x, y ... >>> z = Foo() >>> z.bar(y=3, x=1) 1 3 And even this works: >>> Foo.bar(z, y=3, x=1) 1 3 But why doesn't this work? >>> Foo.bar(self=z, y=3, x=1) Traceback...

How do you test a Rails controller method exposed as a helper_method?

They don't seem to be accessible from ActionView::TestCase ...

- (void)alertViewCancel:(UIAlertView *)alertView is not called

Hi all I've got the problem that the UIAlertViewDelegate method - (void)alertViewCancel:(UIAlertView *)alertView is not called when I cancel a AlertView with it's cancel button. Weird is that the delegate method - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex works perfectly. Does anyone have an ...

Java method help

Ok, so I'm working on a project for a class I'm taking.. simple music library. Now I'm having some issues, the main issue is I'm getting "non-static method cannot be referenced from a static context" Here is a function I have public void addSong() { Scanner scan = new Scanner(System.in); Song temp = new Song(); int index ...

How do I add a method to the Form class in Windows Forms?

I want to add a new method in Windows.Forms.Form class.. Please help how to do this if anyone knows.. ...

Howto UML: sub methods / calls / operations / procedures

I'm not sure how to model sub-methods in UML sequence diagram. When in the execution of one method another method is called (from the same class). I tried to give an example below: How would you guys model this in UML (in a sequence diagram)? .. car1.drive(); .. ... in Car class: .. drive(){ this.startEngine(); } startEngine(){ ...

Silverlight UserControl with rectangle as a button

Hi, I have a problem using custom made UserControl in Silverlight Page. The UserControl is generally a rectangle containing a smaller rectangle inside. I want to use the UControl in a Silverlight MainSite. i've implemented a method on mouse button down for a smaller rectangle called in here Button1: public void Button1_MouseLeftButtonD...

Does iPhone SDK Objective C support functions inside of functions?

I know that javascript, for example supports functions inside of functions, like so: function doSomething(){ function doAnothingThing(){ //this function is redefined every time doSomething() is called and only exists inside doSomething() } //you can also stick it inside of conditions if(yes){ function doSomethingE...

Calling function from popover.

Alright, so I made a popover from my main view and all that good stuff. But I want to have my popover call an action in my main view when a button within the popover is pressed. MainView *mainView = [[MainView alloc] initWithNibName:@"MainView" bundle:nil]; [mainView doStuff]; The "dostuff" function changes some elements within the vie...

GAE - Getting TypeError requiring class instance be passed to class's own method...

I'm really new to programming... I set up a class to give supporting information for Google's User API user object. I store this info in the datastore using db.model. When I call the okstatus method of my user_info class using this code: elif user_info.okstatus(user): self.response.out.write("user allowed") I get this error: un...

How do I Moq It.IsAny for an array in the setup of a method?

I'm brand new to Moq (using v 4) and am struggling a little with the documentation. What I'm trying to do is to Moq a method that takes a byte array and returns an object. Something like: decoderMock.Setup(d => d.Decode(????).Returns(() => tagMock.Object); The ???? is where the byte[] should be, but I can't work out how to make it so...

Objective-C method not being called

It's either because of the fact I'm tired or because I'm doing it wrong, but for some reason I can't get it to call a method. Here's what I'm trying to call: -(void)newHighScore:(int)d Which right now just does an NSLog saying "yea I'm working!" I'm calling it like this: [highscore newHighScore:score]; highscore is what I called ...

method implementation for this case in Java

Hello, I just saw a code snippet like this: private static class DefaultErrorHandler<RT> implements ErrorHandler<RT> { public RT handle(Object[] params, Throwable e) { return Exceptions.throwUncheckedException(e); } Now I am wondering what the static method "throwUncheckedException (Throwable e)" would return exactly and how it...

Enum as a Parameter in Dynamics AX

My report has a parameter which uses a base enum. The enum has 4 different options to choose when running the report. How do I insert an option which uses all 4 at once? For example, I have an enum named Phone and it has 4 types: 1 = None, 2 = Home, 3 = Mobile, 4 = Work. In a drop down, how do I add option 5 = None+Home+Mobile+Work? T...

The cost of nested methods

In Scala one might define methods inside other methods. This limits their scope of use to inside of definition block. I use them to improve readability of code that uses several higher-order functions. In contrast to anonymous function literals, this allows me to give them meaningful names before passing them on. For example: class Agg...