methods

Disabling a method - iPhone

I want to disable a method from running if my audio clip is playing. I have myImage.hidden working if the audio.playing is running, how would I go about disabling a method in the same way? if (audio.playing == YES) { // image is hidden myImage.hidden = YES; } ...

Methods: What is better List or object?

While I was programming I came up with this question, What is better, having a method accept a single entity or a List of those entity's? For example I need a List of strings. I can either have: a method accepting a List and return a List of strings with the results. List<string> results = methodwithlist(List[objects]); or a m...

Polymorphism in Python

class File(object): def __init__(self, filename): if os.path.isfile(filename): self.filename = filename self.file = open(filename, 'rb') self.__read() else: raise Exception('...') def __read(self): raise NotImplementedError('Abstract method') class FileA(Fi...

Java Modulo Help

public void turnRight() { int direction=getDirection(); if (direction==3) direction=0; else direction++; this.setDirection(direction); So I have this method that, when called, increments direction by 1. However, the max value should be 3, so if direction is equal to 3 and the meth...

"method" method in Crockford's book: Javascript: The Good Parts

Douglas Crockford wrote in his book (Page 4): Throughout the book, a method method is used to define new methods, This is its definition: Function.prototype.method = function (name, func) { this.prototype[name] = func; return this; }; Then he starts to use this method to add method in Number, String, Function, Object, Array, ...

Is there a way to call external functions from xaml?

Is there any way to call methods of external objects (for example resource objects) directly from xaml? I mean something like this: <Grid xmlns:dm="clr-namespace:MyNameSpace;assembly=MyAssembly"> <Grid.Resources> <dm:TimeSource x:Key="timesource1"/> </Grid.Resources> <Button Click="timesource_updade">Update time</But...

method invoked or method called ?

I am not sure if this question is relevant but I see the expression "the method is invoked" a lot , So Is there a technical difference between invoking a method or calling a method or It's just other word for the same action ? P.S : Clearly , I am not an English native speaker and looking for invoke definition on the web didn't help . ...

Is it possible to determine which class a function is a method of?

For example, if I'm decorating a method like so def my_decorator(fn): # Do something based on the class that fn is a method of def decorated_fn(*args, **kwargs): fn(*args, **kwargs) return decorated_fn class MyClass(object): @my_decorator def my_method(self, param): print "foo" Is it possible i...

Calling parent method from within the parent class

Here's an excerpt from my code package dictionary; import java.util.Iterator; import java.util.LinkedList; import java.util.regex.*; public class IntelliCwDB extends CwDB { public IntelliCwDB(String filename) { super(filename); } @Override public void add(String word, String clue) { System.out.println...

Executing a method by parameter in C#

I'll start by I have no idea on the terminology on this or if it is even possible (I am pretty sure it can be done). I have a chunk of code that is basically as follows: DataTable dt = new DataTable(); if (string = "this") dt = method1(); else if (string = "that") dt = method2(); else if (string = "somethingelse") dt = met...

Rails: Adding methods to models to perform checks based on current_user?

I have a model that looks something like this: class Comment < ActiveRecord::Base ... #allow editing comment if it is moderated and the user passed-in #is the one that owns the comment def can_edit?(user) moderated? and user.Type == User and user.id == self.user_id end ... end And a call in a view: <%= link_to 'Show C...

C# Beginner, writing/calling a Method

When we write a method, say an easy one like void myMethod() { // code here // } and we call it from within Main(), it's done essentially this way: Program myProgram = new Program (); myProgram.myMethod(); Obviously, myProgram is entirely arbitrary (taking into consideration, of course, coding conventions) but w...

Getting scheduler from another method (Quartz.NET). Or general method question.

Hi all, this may be a general question on sharing variables but here goes. I'm using a GridView on a webpage to edit each job, and I need to hook up to each 'rowbound' event to get some data from the jobDataMap. Anyway, the scheduler starts in the Page_Load method (creating the variable sched I can use to access the info), but from an...

Best way to check function parameters: Check for null or try/catch

Hello everyone, when implementing/using methods that return or work with instances of objects, what is the most elegant approach to check the function parameters ? Method to call: someType GetSomething(object x) { if (x == null) { return; } // // Code... // } or better: someType GetSomething(object x) {...

Method with boolean return - if else vs. if

Take for example the following two statements: if (booleanVariable) { doSomething(); return true; } else { return false; } and if (booleanVariable) { doSomething(); return true; } return false; Which one would be preferred? They both return the same result in the end. Any reason one would be better to use than the ot...

Does C# support multiple return values?

The noob here again. This is a very basic question, and if what I am thinking of doing is complicated/involved, then I don't expect you to go into detail... I've read that this may involve structs or hash or some other scary procedure I've not gotten to yet. If so, I'm sure it'll get me soon. Working on learning classes, methods, and re...

Java static method can't compile

Hi, the following messege appears when I compile this code. ExtractChars(java.lang.String,int) in Question2 cannot be applied to () What should I fix? Thanks. import java.util.Scanner; public class Question2 { public static void main (String[] args) { ExtractChars(); } public static String ExtractCha...

Exception when running a Python method from another class.

Here is my code. import urllib2 import urllib import json from BeautifulSoup import BeautifulSoup class parser: """ This class uses the Beautiful Soup library to scrape the information from the HTML source code from Google Translate. It also offers a way to consume the AJAX result of the translation, however encodi...

Can I define a nameless method in a Scala class?

Is this possible to reach? If yes, please correct my Foo declaration syntax. class Foo (...) { ... def /* the nameless method name implied here */ (...) : Bar = new Bar (...) ... } class Bar (...) { ... } val foo : Foo = new Foo (...) val fooBar : Bar = foo (...) ...

How can I fetch the same URL with different query string with Perl's LWP::UserAgent?

I looked up articles about using LWP however I am still lost! On this site we find a list of many schools; see the overview-page and follow some of the links and get some result pages: I want to parse the sites using LWP::UserAgent and for the parsing : want to use either HTML::TreeBuilder::XPath or HTML::TokeParser At the moment I am ...