methods

Cocoa: Calling a method from AppDelegate.m

In order to better understand the startup, event queue, and methods within my application I'm trying to write a program that does two things: Play a beep at the startup and every time the user hits a button. So far it only plays when the user hits the button. I know there may be multiple ways to get the startup beep to play, but in ord...

Ruby: what method is called?

Assume, I have an object x of MyClass. What method is called, when I do puts x? I need to override it with my own one. I thought it was .inspect, but somehow overridden inspect isn't being called. For example, I have a class Sum: class Sum initiazlie a, b @x = a + b end end And I wanna access the result like this: s = Sum...

How would you define a simple "min" method in obj-c

I want to define a min and max methods in a Utils class. @interface Utils int min(int a, int b); int max(int a, int b); @end But I don't want to have named parameters. It would be a too heavy notation. I wanted to use the C-style definition. But then [Utils min(a, b)] as a call doesn't work. What is my problem? Thanks in advance fo...

Ruby: catching access to variable inside class

I have a class, which de-constructs incoming string into a nested array cascade. For example for an input abcde it will produce a [[[[a,b],c],d],e] array. Just now, if I access to set any top level value of cascade, the []=(index, value) method of my class will be invoked. But I also need to catch the access to the nested array within c...

Dynamically assign special methods to objects but not classes in Python

I would like to do the following: class A(object): pass a = A() a.__int__ = lambda self: 3 i = int(a) Unfortunately, this throws: Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: int() argument must be a string or a number, not 'A' This only seems to work if I assign the "special" method to the ...

COM - How to create a method that returns a pointer to an interface?

How to create a method in COM that returns a pointer to an interface, this needs to be done inside the IDL file. EDIT: How do I implement this within a class: STDMETHODIMP CBlah::get_Something(IOtherBlah** retval){ return m_protectedvar->QueryInterface(retval); } STDMETHODIMP CBlah::put_Somthing(IOtherBlah* rhs){ m_protectedvar = rhs;...

Recursive silverlight Element finder extension method

I need an extension method to traverse all Textboxes on my Silverlight page. Assume I always use a grid Layout, then I have: public static IEnumerable<UIElement> Traverse(this UIElementCollection source, Func<Grid, UIElementCollection> fnRecurse) { foreach (UIElement item in source) { yield return item; ...

Method names for getting data

Warning: This is a not very serious question/discussion that I am posting... but I am willing to bet that most developers have pondered this "issue"... Always wanted to get other opinions regarding naming conventions for methods that went and got data from somewhere and returned it... Most method names are somewhat simple and obvious.....

Calling .Net Classes from Visual Basic 6

Hi, I have a .net dll file. I have to call one of the methods in this dll file from a VB program. This dll file uses another .net dll file for logging purpose. I able to call a .net class library method from VB6 application. But, I am getting the exception that unable to load assembly (which is used for logging). How the vb6 applica...

how do I stop further methods in a PHP class?

I am learning OOP with PHP. I am creating a class to extract XML data from a website. My question is how do I stop the given object from executing more methods if there is an error with the first method. For example, I want to send the URL: class GEOCACHE { public $url; public function __construct($url) { $this->url=$url...

objective-c (iphone sdk) access instance method from separate class

Hi guys I know this is a pretty well posted thing to do, but I still can't work it out. I have an instance method saveAllDataJobs in Jobs.m. - (void) saveAllDataJobs { ... } I am in DetailViewController.m and I want to run the method saveAllDataJobs, which is in Jobs.m. What precisely do I need in order for this code to run. Sorry f...

invoking method declaration without reflection

I have a base class (order) with a set of sub classes (productorder, specialorder, partsorder etc). Only Some of these sub classes implement a particular interface (ITrackingCustomer) which has a single method declaration (object getcustdetails()). As part of my solution all of my orders are processed in a central place, i.e. any cru...

Method return type String is not a String

First of all, my target here is to read from a URL, parse it, and take information from it and give it to another method sendMessage which then sends it to an IRC client. I haven't been doing java long so I'm adapting things I code I find on the internet. The below methods work when they are declared in their own class file, and run by p...

C#: Overidden methods with Security Attributes in .Net 4

In .Net 4 some methods are now decorated with different security attributes than they were in previous versions (ie the new SecurityCriticalAttribute). In order to override methods with security permissions the relative security accessibilities on the derived declaration must match those on the base declaration (or else a runtime excepti...

c# generic method overload not consistent with abstract Visitor pattern

Hello *, experimenting with Visitor pattern and generic method I found a kind of discrepancy in C#.NET. AFAIK C# compiler prefers an explicit overload to a generic method, therefore the following code: public abstract class A { public abstract void Accept(Visitor v); } public class B : A { public override void Accept(Visitor v...

C#: Method signatures?

Let's say I create these two methods: public void AddScriptToPage(params string[] scripts) { /*...*/ } public void AddScriptToPage(string href, string elementId) { /*...*/ } Which one of these methods gets call by the code below, and why? AddScriptToPage("dork.js", "foobar.js"); How does the compiler determine which method to call?...

Singleton's stateless instance method thread safety (C#)

Is it thread safe to make Converter a singleton? public interface IConverter<TFoo, TBar> where TFoo : class, new() where TBar : class, new() { TFoo ToFoo(TBar q); TBar ToBar(TFoo q); } public class Converter : IConverter<Foo, Bar> { public Foo ToFoo(Bar b) {return new Foo(b);} public Bar ToBar(Foo f) {return new...

Delphi: Prevent method names from appearing in exe

I am writting some class, that is for handling security in my exe (checking serials, trial date check etc). After I compile exe even in Release build with all debug and RTTI generation turned off, when I open my exe in NotePad and search method name in a raw data, I can see all the name of the methods, that assemble my class. There is no...

Java JNI - Calling object method.

Hi, I'm currently programming an interface between some C++ code and Java using JNI. I'm getting some events in my GUI that I want to pass to a C++ event handler. I therefore call a function that I wrote in Java. public void sendToEventQueue( AWTEvent evt ) { Mudkiptz.Main.fctC_sendEvent( evt ); } This method is in an abstract cl...

Polymorphism - adding to existing methods while overwriting them

I want to be able to subclass a class, and define __init__ but still run the old __init__ as well. To illustrate, say I have the following classes: class A(object): def __init__(self): self.var1 = 1 class B(A): def __init__(self) self.var2 = 2 doInitForA() And I want to be able to do this: instB = B(...