Some Syntax Differences


Ruby Way
By Hal Fulton
Slots : 1.0
Table of Contents

Ruby syntax does not require indentation. The keyword end is used for demarcation of code blocks starting with begin, case, class, def, do, if, for, and others. Notice the absence of colons.


 if x == 5   puts "Five Golden Rings"  end 

You can use semicolons to separate statements on a single line, and lines can continue onto the next line.


 a=[2,4,  3]; for i in a; puts "%d  " % i; end 

If the breaking point is too ambiguous for Ruby, you can make it explicit by using the \ continuation character.

Ruby supports shell-type comments using #, and also special =begin and =end tags for making documentary or temporary multi-line comments. There is no built-in equivalent to Python's doc strings.




The Ruby Way
The Ruby Way, Second Edition: Solutions and Techniques in Ruby Programming (2nd Edition)
ISBN: 0672328844
EAN: 2147483647
Year: 2000
Pages: 119
Authors: Hal Fulton

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: