methods

What does the registerNatives() method do?

In java, what does the private static method registerNatives() of the Object class do? ...

C# - new keyword in method signature

While performing a refactoring, I ended up creating a method like the example below. The datatype has been changed for simplicity's sake. I previous had an assignment statement like this: MyObject myVar = new MyObject(); It was refactored to this by accident: private static new MyObject CreateSomething() { return new MyObject{"Som...

Python: Bind an Unbound Method?

In Python, is there a way to bind an unbound method without calling it? I am writing a wxPython program, and for a certain class I decided it'd be nice to group the data of all of my buttons together as a class-level list of tuples, like so: class MyWidget(wx.Window): buttons = [("OK", OnOK), ("Cancel", OnCancel)] ...

F# Private Static Methods

How do i define a private static method in a class in f#? when i try to attach a private modifier it complains. ...

How can I replace (wrap) methods in new methods programmatically?

I have several methods that I need to wrap in new methods in basically the same manner. My first solution doesn't work, and I understand why, but I don't know if there is a simple solution to this problem or if it can't be done the way that I want to do it. Here's an example. I have objects a-c that have an onClick method. I need to exe...

how to set default method argument values?

Hi, Is it possible to set the default method parameter values in Java? Example: If there is a method public int doSomething(int arg1, int arg2) { //some logic here return 0; } is it possible to modify the given method in order to be able to call it with and without parameters? example: doSomething(param1, param2); doSomething(); ...

Mutiple Methods, or parameters?

Ok, so I am designing a class here and I have two options. I can either write multiple methods or a single method which takes say an Enum. I'm trying to figure out the best way to do this. Lets take an example: public class myClass { ... public void DoStuff1() { ... Do Stuff ... } public void DoStuff2() { ... Do Stuff...

Can a Ruby method yield as an iterator or return an array depending on context?

I have an arbitrary method in Ruby that yields multiple values so it can be handed to a block: def arbitrary yield 1 yield 2 yield 3 yield 4 end arbitrary { |x| puts x } I'd like to modify this method so that, if there is no block, it just returns the values as an array. So this construct would work as well: myarray = arbitr...

Objective-C: Class vs Instance Methods?

Hi, What's the difference between a class method and an instance method? Are instance methods the accessors (getters & setters) while class methods are pretty much everything else? Thanks, ...

How do I make my public static logging method write to an inputfield?

I figured out how to create a static method that is available everywhere, for example: UtilLib.as: package { public final class UtilLib { public static function getTimeStamp():uint { var now:Date = new Date(); return now.getTime(); } } } I can access this...

Importing methods for a Python class

I wonder if it's possible to keep methods for a Python class in a different file from the class definition, something like this: main_module.py: class Instrument(Object): # Some import statement? def __init__(self): self.flag = True def direct_method(self,arg1): self.external_method(arg1, arg2) to_import_f...

Method calls and declarations in objective-c for cocos2d-iphone

I am an absolute objective-c, c, and openGL newbie. Hence, when I found coco2d I was pretty thankful for having a lot of stuff done for me. Regardless, I'm still having issues. After I managed to get an animated sprite moving around based on touches I decided to clean up my code a bit into a updateLogic method and than a updateDrawing ...

How to write a method/message with multiple parameters?

How do you write a method/message with multiple parameters? EDIT: Like multiple parameters for a single method/message, I mean. ...

How do you evaluate new technology?

Hello, when you (or your company) comes to the point to choose a technology for a new product to develop: What are your basic steps/approaches to evaluate it's use? To make it more clearer: Which factors should an architect/cto consider (e.g. costs, integration in exisiting system...)? Which methods are available (e.g. prototyping)? ...

Ruby call method from hash

Hey, I asked a little earlier about a clever way to execute a method on a given condition see here The solutions (and response time!) was great, though upon implementation having a hash of lambdas gets ugly quite quickly. So I started experimenting. The following code works: def a() puts "hello world" end some_hash = { 0 => a() } s...

Ruby: obtaining number of block parameters

Hi there. I have a rather unusual use case whereby I need to be able to obtain the number of parameters a given block has been defined to take. For example... foobar(1,2,3) { |a, b, c| } def foobar(x, y, z, &block) # need to obtain number of arguments in block # which would be 3 in this example end From what I understand, this is...

For Objective-C ... Pointer to method

I want to setup a Method dispatch table and I am wondering if it is possible to create pointer to a method in Objective-C (like pointer to function in C). I tried to use some obj-c runtime functions to dynamically switch methods but the problem is it will affect all instances. As I am very new to obj-c, an illustrated example would be ...

Invoking the click method of a button programmatically

Simple problem (I think): I want to be able to invoke a click method on a predefined object, specifically, the bindingNavigatorDeleteItem button on the standard c# BindingNavigator. I need to intercept the delete so that I can verify that the record is allowed to be deleted. If it is, I want to invoke the aforementioned click event which...

Decorator to mark a method to be executed no more than once even if called several times

I will go straight to the example: class Foo: @execonce def initialize(self): print 'Called' >>> f1 = Foo() >>> f1.initialize() Called >>> f1.initialize() >>> f2 = Foo() >>> f2.initialize() Called >>> f2.initialize() >>> I tried to define execonce but could not write one that works with methods. PS: I cannot define the code ...

How to test if a class attribute is an instance method.

In Python I need to efficiently and generically test whether an attribute of a class is an instance method. The inputs to the call would be the name of the attribute being checked (a string) and an object. hasattr returns true regardless of whether the attribute is an instance method or not. Any suggestions? For example: class Test...