>>>>> "Phil" == Phil Tomson <ptkwt / user2.teleport.com> writes:
Phil> Being very new to Ruby (2-3 days) and very familiar with
Then, may I welcome you here? We really appreciate everyone who wants
to give it a try :-)
Phil> Perl, I tend to prefer { .. } for block delimiters. From
Yes ... but see below ...
Phil> what I can tell in Ruby you can use either do .. end or {
Phil> .. } for blocks. What if that flexibility was also allowed
Phil> for method definitions so that you could have:
Phil> def somemethod { ... }
Phil> in addition to the current syntax:
Phil> def somemethod ... end
And here is one BIG difference between Ruby and Perl. In Perl the {
... } are merely block delimiters. You are right! And so for Ruby's
usage of { ... }.
BUT in Ruby a block (let me call it R-BLOCK) is a TOTALLY DIFFERENT
thing as a block in Perl (P-BLOCK). A P-BLOCK only groups statements
in the source and is only used via compilation stage to determine such
groups of statements!
R-BLOCKs, however, constitutes REAL OBJECTS that happen to CONTAIN
code. Only the R-BLOCKs objects are not DIRECTLY accessible like any
other object. You may access them via:
yield : Calling an associated block
block_given? : Check if an block is associated
proc | lambda | Proc.new : Convert a block to a Proc instance
&var : - In formal parameter list, convert attached block to a Proc
instance and pass that to 'var'
- In an actual parameter list, converts a Proc instance back
to a R-BLOCK object.
Whereby a Proc instance is something similar to Perl's sub reference:
sub { ... };
To stress it again, that do ... end and { ... } constitutes REAL
objects, that can be dealt with.
Statements like 'def', 'if', 'for', etc. that need only statement
grouping, but not no R-BLOCK objects, will have the different
syntax/convention, that the statement opens the grouping and a
corresponding 'end' will close it.
You see, no easy way to get Perl's or C/C++'s behavior here!
I hope you will anyway find fun with Ruby :-)
(...)
Phil> Phil
\cle