methods

What is the difference between jQuery's functions val() and text()?

I think the question says it all. Where would you use one over the other? Thanks! ...

How do I put optional parameters in methods?

Is it possible to declarate optional parameters in methods? In delphi,for example,I can do something like: procedure Test(p1:integer;p2:integer;p3:integer = 2;p4:integer = 4) When I call that function I can call it with four parameters or with two parameters: Test(2,3); //p3 = 2,p4 = 4. Test(2,3,4,5); //p3 = 4,p4 = 5; How is that ...

Java methods and classes, how do they fit together? (Solved)

Currently I am writing a program for an introductory Java class. I have two pieces to my puzzle. Hopefully this is a relatively simple to answer question. Firstly, here is what I am trying to use as my main program: import java.util.Scanner; public class TheATMGame { public static void main(String[] args){ Scanner input = new S...

how do i check for the existence of a method in a rails application controller?

Hi All, In my application controller, I have a method that is supposed to check for the existence of another method in a subclassed controller to set the filename of a downloaded file, but i'm having trouble making it work properly i've tried def filename begin send "filename_method" rescue NoMethodError default_filename ...

how do i pass multiple arguments to a ruby method as an array?

Hi All, I have a method in a rails helper file like this def table_for(collection, *args) options = args.extract_options! ... end and i want to be able to call this method like this args = [:name, :description, :start_date, :end_date] table_for(@things, args) so that I can dynamically pass in the arguments based on a form commit...

Cached or precomputed Immutable Functions in C# / C++

By "immutable function" or "immutable method", I mean a function whose result will never vary if you give it the same arguments. I would be interested to know if anyone know of a more generic or less verbose solution when you want to cache the precomputed value(s) of an immutable function. Let me explain what I mean with a simple examp...

generic extension method

I am working on this mvc project following Rob Connery's storefront video series and applying the techniques. On the filtering and extensions methods, i started repeating myself a lot such as: public static Sponsor WithID(this IQueryable<Sponsor>qry, int ID) { return qry.SingleOrDefault(s => s.ID== ID); } public static Keyword With...

Why would only the prefixing return type of a java method execute ?

Hi, I am trying to understand some java code which for some reason appears to execute its return type class (the SQLExecutionInfo class) and nothing else within the method. Perhaps this is simply how the java works (i.e regardless of whether of what is within the method body the type of class being returned is first executed ??) The m...

Ruby Difference Between Integer Methods

What is the difference between 10.6.to_i and 10.6.to_int ? ...

Factory method pattern in java using generics, how to?

I have code that looks like follows: public interface BaseDAO{ // marker interface } public interface CustomerDAO extends BaseDAO{ public void createCustomer(); public void deleteCustomer(); public Customer getCustomer(int id); // etc } public abstract class DAOFactory { public BaseDAO getCustomerDAO(); public static DAOFactory getIn...

How to pass a method as parameter without declaring a delegate in .NET

No matter how I try, I cannot mimic the clean syntax of Rhino Mocks, without declaring a delegate. Example: Expect.Call(service.HelloWorld("Thanks")) Do you have any idea on how to do this? Thanks. ...

Best way to Find which cell of string array contins text

I have a block of text that im taking from a Gedcom (Here and Here) File The text is flat and basically broken into "nodes" I am splitting each node on the \r char and thus subdividing it into each of its parts( amount of "lines" can vary) I know the 0 address will always be the ID but after that everything can be anywhere so i want ...

ASP.Net page methods execution time monitoring.

could anybody advice me, are there any approaches to calculate the methods execution time in asp.net page? ASP.Net Trace doesn't suit me since it ignores ajax partial postbacks though just they are the tight place. I have the page event which for some unknown reason executes slowly. Since the logic and event execution chain is rather c...

(N is unknown) $controller->$action($param1, $param2, $param3... $paramN);

(N is unknown) $controller->$action($params); must be $controller->$action($param1, $param2, $param3... $paramN); ...

A class method which behaves differently when called as an instance method?

I'm wondering if it's possible to make a method which behaves differently when called as a class method than when called as an instance method. For example, as a skills-improvement project, I'm writing a Matrix class (yes, I know there are perfectly good matrix classes already out there). I've created a class method for it called identi...

Objective-C Default Argument Value

Hey there, quick question here. I'm sure there's a simple answer. Coming from PHP, I'm used to declaring a function with a default argument value like this: function myFunction ($array, $sort = FALSE) { } I the sort parameter wasn't filled, the function would continue with the default value of false. In Obj-C, is there a similar t...

How to create a method for an array class?

Sorry, I know this is programming 101, but I can't find any good documentation... I have an array, and I want to cast each member as an object and then call them by the name assigned (this would be so much simpler if javascript allowed for non-number index values). For instance: var things = ['chair', 'tv', 'bed']; var costs = ['10',...

What is the difference between an Algorithm and a Method

How do you differentiate between an algorithm and a method? Why dont we call Newton's Method or Ford-Faulkerson method Algorithms? What are a properties of a good algorithm and what qualifies a method as an algorithm? ...

How do you know when looking at the list of attributes and methods listed in a dir which are attributes and which are methods?

I am working through trying to learn to program in Python and am focused on getting a better handle on how to use Standard and other modules. The dir function seems really powerful in the interpreter but I wonder if I am missing something because of my lack of OOP background. Using S.Lotts book I decided to use his Die class to learn m...

Difference between a Local Variable and a Variable Called from a Method? C#

I would like to know whats faster. Help me out. I have a variable declared in a Method like so: public static Regex FindNumber() { return new Regex(@"\d+", RegexOptions.IgnoreCase | RegexOptions.Compiled); } As you can see it returns a Regular Expression. I also have another Method that looks like so: private static string...