From: "David A. Black" Date: 2008-12-13T18:11:19+09:00 Subject: Re: Function def at end of scripts --1926193751-652234746-1229159907=:9772 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-652234746-1229159907=:9772" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-652234746-1229159907=:9772 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Sat, 13 Dec 2008, Einar Magn=FAs Boson wrote: > > On 13.12.2008, at 00:02 , ara.t.howard wrote: > >>=20 >> On Dec 12, 2008, at 10:06 AM, No Where wrote: >>=20 >>> Hi, >>>=20 >>> I am refactoring an ugly script. I would like it contained all in one >>> file so I was moving code to functions/classes and put them at the end >>> of the script for legibility. This didn't work. They are only available >>> if I put them at the beginning of the script before I need them. Is >>> there a way to declare them at the beginning so I can put them all at >>> the end of the file? >>>=20 >>> Thanks! >>> Eric >>> --=20 >>> Posted via http://www.ruby-forum.com/. >>>=20 >>=20 >>=20 >> stuff >>=20 >>=20 >> BEGIN { >> def stuff >> end >> } >>=20 >> a @ http://codeforpeople.com/ >> -- >> we can deny everything, except that we have the possibility of being=20 >> better. simply reflect on that. >> h.h. the 14th dalai lama >>=20 >>=20 > > > #!/usr/bin/env ruby -wKU > END { > =09puts=20 > "http://www.java2s.com/Code/Ruby/Statement/Thecodeinablocklabeledwiththek= eywordBEGINisrunautomaticallywhenaRubyprogramisloaded.htm"=20 > } > > stuff > > BEGIN { > =09def stuff > =09=09puts "who would've guessed?" > =09end > } > # >> who would've guessed? > # >>=20 > http://www.java2s.com/Code/Ruby/Statement/Thecodeinablocklabeledwiththeke= ywordBEGINisrunautomaticallywhenaRubyprogramisloaded.htm > > This is cool. Thanks! It can serve a purpose, but please have mercy on those of us who like our Ruby in order :-) It's really not that hard to get used to the principle that the code (including method definitions) is executed as it's encountered, and then you don't have to think about whether or not to flip it. David --=20 Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS (Jan 12-15), Fort Lauderdale, FL See http://www.rubypal.com for details Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2) --1926193751-652234746-1229159907=:9772-- --1926193751-652234746-1229159907=:9772--