From: Bira Date: 2008-05-08T01:38:06+09:00 Subject: Re: Script not working On Tue, May 6, 2008 at 9:54 AM, Pranjal Jain wrote: > HI All > I am having a script which is not working when I am writing it inside a > method > def addcomment. But when I am writing it outside the method; it starts > working. Can somebody explain me why this is so? When you define a method, it's not automatically executed by Ruby. So, if you want that code to run when the script is executed, you have to call the method in the main body of the script (or just put the code directly into the main body of the script, as you have done). Example: def add_comment # code goes here end if __FILE__ == $0 add_comment # calls the method if we're running the script. end -- Bira http://compexplicita.wordpress.com http://compexplicita.tumblr.com