From: Mark Bilk Date: 2009-04-10T04:02:11+09:00 Subject: Re: Calling a Function Before It's Defined Joel VanderWerf wrote: > foo > BEGIN { > def foo; end > } Thanks! Just to make it clear for other beginners like me, here's the fixed version of my code: ------------------- s = "abc" f(s) BEGIN { def f(x) print('f: ', x, "\n") end } ------------------- Quoting _Programming Ruby_ (the Pickaxe book): BEGIN and END Blocks Every Ruby source file can declare blocks of code to be run as the file is being loaded (the BEGIN blocks) and after the program has finished executing (the END blocks). BEGIN { begin code } END { end code } A program may include multiple BEGIN and END blocks. BEGIN blocks are executed in the order they are encountered. END blocks are executed in reverse order. -- Posted via http://www.ruby-forum.com/.