From: David Alan Black Date: 2001-08-15T03:27:33+09:00 Subject: [ruby-talk:19717] Re: and in postconditions Hello -- On Wed, 15 Aug 2001, Joel Wilsson wrote: > Hi everyone, > I've found something very strange. "and" doesn't > seem to do what I expect it to do when used with postconditions. > In Perl, however, it does. > > $ cat test.pl > sub test($) { > my $i = shift; > print "TRUE!\n" and return true if ($i > 10); > print "FALSE!\n"; > return false; > } > print test(20), "\n"; > print test(2), "\n"; > > $ perl test.pl > TRUE! > true > FALSE! > false > > $ cat test.rb > def test i > print "TRUE!\n" and return true if (i > 10) > print "FALSE!\n" > return false > end > print "#{test(20)}\n" > print "#{test(2)}\n" > > $ ruby test.rb > TRUE! > FALSE! > false > FALSE! > false > > $ ruby -v > ruby 1.6.4 (2001-07-31) [i386-freebsd5.0] > > Could someone please explain why Ruby behaves like this? > Is there a reason for it, or is it a bug? On success, Ruby's print returns nil, whereas Perl's returns true. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav