methods

calling a method from another method in same PHP class

Hi, I'm trying to use a method from within another method in a class. I don't have much experience in PHP5 OOP, and I looked around for answers, but couldn't find any. I'm trying to use getClientInfo() in sendRequest(), which is in the same class. class DomainHandler { public static function getClientInfo($db, $client_id) { ...

Object wont update

Hay all, my object doesnt seem to update when i call the save() method heres my code car = Car.objects.get(pk=car_id) car.views += 1 car.save() and the model views = models.FloatField(max_length=1000) I do have a save() override method, could this cause a problem? def save(self): d = timedelta(days=self.expires_in...

How to refer to a method name from with a method in Python?

Say I have the following class defined with the method foo: class MyClass: def foo(self): print "My name is %s" % __name__ Now when I call foo() I expect/want to see this printed out My name is foo However I get My name is __main__ And if I was to put the class definition into a module called FooBar I would g...

Passthrough Methods

Does anyone know of a way of providing pass-through methods to provide something like the following but with added DRY? class Cover @some_class = SomeClass.new def some_method @some_class.some_method end end ideally I would like to dry it up to something like this: class Cover @some_class = SomeClass.new passthrough...

How to dynamically create arguments for a method?

Being still somewhat new to Ruby, I'm not sure how to do this... Let's say I have a method that takes a variable number of arguments: def mytest(*args) puts args.to_json end Obviously I can call it with whatever I like, such as: mytest('one', 'two', 'three') No problem. But what I need to do is call it with a dynamically-created se...

In javascript, how do I call a class method from another method in the same class?

I have this: var Test = new function() { this.init = new function() { alert("hello"); } this.run = new function() { // call init here } } I want to call init within run. How do I do this? ...

how does the following code work

Currently I'm trying to invoke it like this: class Test { public static void test() { System.out.println("hi"); } public static void main(String[] args) { Test t = null; t.test(); } } The output of the code is hi ...

Getting the instance that called the method in C#

I need to have an algorithm that can get the object a method within the method like this: public class Class1 { public void Method () { //the question object a = ...;//the object that called the method (in this case object1) //other instructions } } public class Class2 { public Class2 () { ...

quick-and-dirty way to pass a method with parameters, as a parameter?

Let me just preface this with the fact that I'm pretty green to C#. That being said, I'm looking for a way to pass a method with a parameters as a parameter. Ideally, what I want to do is: static void Main(string[] args) { methodQueue ( methodOne( x, y )); } static void methodOne (var x, var y) { //...do stuff } static void ...

Fictitious jQuery persist method

Is there a way to have a declaration such as the following persist to all matching elements that are later added to the DOM? $("a.my-class").replaceWith("<span>Replaced</span>"); Something along the lines of... $("a.my-class").persist().replaceWith("<span>Replaced</span>"); (Persist is a fictitious method, that I hope conveys what ...

Python String Method Conundrum

The following code is supposed to print MyWords after removing SpamWords[0]. However; instead of returning "yes" it instead returns "None". Why is it returning "None"? MyWords = "Spam yes" SpamWords = ["SPAM"] SpamCheckRange = 0 print ((MyWords.upper()).split()).remove(SpamWords[SpamCheckRange]) ...

Need a self. method on a Rails model using Acts_as_list

I am still newer to Rails... I need to write a self.method on my Product model to find the next Product per position. I am showing 1 Product on a page, and want the next one in the list. def self.next_product product = Product. # current product.position +1 end obviously this won't work... I am still new to writing methods. anyone? ...

iPhone NSURLConnection: connectionDidFinishLoading - how to return a string to the calling method.

Hi Guys, Could you please help me? I have reviewed similar stackoverflow questions/answers to this but I am still stumped. I'm a beginner and I'm really struggling with this. With the iPhone, I can download XML from a URL but I cannot store the result string in a NSString variable and see it from the calling function. I have the follo...

What is wrong with this method? (I need some awesome Ruby Coders)

Ignoring rolerequirement with restfulauthentication method in a subdomain scope I have created a site which utilizes subdomains and searches whether or not the user is at: subdomain.domain.com or domain.com. If the user is in subdomain.domain.com, /views/layouts/application.html.erb appears, if the user is in domain.com /views/layouts/p...

Getting undefined method `username' for #<UserSession: no credentials provided> with Authlogic after push to production

We've never gotten this app to run in production. The application runs just fine in dev. I've made sure all rake tasks are up to date and acts_as_authentic is set for the user and everything else that everyone has posted on all the forums. The server has been bounced multiple times. This error comes up every single time on all URLs. ...

what does this refer to in a javscript private method

Using the following bit of code: function Node(){ .... function foo(request){ for (var name in this ) { log(name +" is "+this[name]); if(!(name == 'all' || typeof this[name] == 'function')){ request[name] = this[name]; } } return ... }; } I was surprise...

Static Method of a Static Class vs. Static Method of a Non-Static Class ( C# )

I was asked the above question in an interview. Could you please explain the differences? ( performance - memory - usage - when to use which ? ) Thank you, Erkan ...

Good naming convention for functions and methods which may modify (write back to) a parameter.

Hello, everyone! I need to find a good and understandable naming-scheme for routines which deal with "value arrays" (I've written something similar to C++'s valarray in Java, with some optimizations for primitive types in mind). I know that the main categorization of routines is made between: functions (they may take parameters and m...

Is there any way to check if a POST url exists?

Is there any way to determine if a POST endpoint exists without actually sending a POST request? For GET endpoints, it's not problem to check for 404s, but I'd like to check POST endpoints without triggering whatever action resides on the remote url. ...

What is the use of creating functions within functions?

I know that it is possible to create a function within another function. Why might one need to do that in real life? (PHP) function someFunction($var) { function anotherFunction() { return M_PI; } return anotherFunction(); } ...