From: Daniel Carrera Date: 2002-11-21T02:30:13+09:00 Subject: Re: Learning Ruby > >I noticed that Ruby doesn't let me use functions until after I define > >them (unlike Perl)... > > But even with Perl, don't you have to pre-declare the function prototype? Nope. The following works: #!/usr/bin/perl hello("Daniel"); sub hello { $name = $_[0]; print "Hello $name\n"; } > Yes, in Ruby [snip] you can do things like: > > if RUBY_PLATFORM =~ /win/ > require "Win32Defs" > elsif RUBY_PLATFORM =~ /nix/ > require "UnixDefs" > end > > OR, [snip] > if ENV['FOO'] && ENV['FOO'] == "true" > require 'foo' > include FooMod > elsif ENV['BAR'] && ENV['BAR'] == "true" > require 'bar' > include BarMod > end > > It's probably not as easy to do that sort of thing in Perl because there > is a seperate compile phase. But, I have to admit, it's been a while so I > wouldn't be surprised if there is a way of doing this in Perl. Actually, the same things would work with Perl's "require", but AFAIK not with "use". But this points to a difference between Perl and Ruby. Take the following Perl code: sub hello { print "hello" } hello; sub hello { print "hi" } hello; This will print: hi hi Where as the Ruby version would print hello hi So I can see a bit of a trade-off. Ruby allows me to redefine functions at run-time, which can be very cool. For instance, I can make a "vector" class, and redefine the method "+" several times to correspond to different metrics. Thank you all for the help. The resources are very good. Daniel.