Today I learnt the basics of Ruby...
A program written in Ruby will have a file extension with .rb(not mandatory)
Ruby program execution goes from Top-Down approach
Syntax rules in Ruby...
1.Free format
2.Case Sensitive ( AB and ab or not the same..)
3. Single line comment can be given using #, Multiple line comment using =begin and = end
Example 1(using 1- line comment) :
puts " Leader" # This is a Ruby code which outputs "Leader"
Example 2 (Using multiple line comment)
puts "Leader"
=begin
'puts' means put a string
It outputs the string in the quotes
=end
4. No delimeter for a single line.....but should use semicolon(;) for multiple statements in one line
Example 1 : puts "Leader" output : Leader
Example2 : puts "Gandhi"; puts "is a great Leader" output : Gandhi is a great Leader
Linefeed is treated like a semicolon
If a line ends with a backslash (\), the linefeed following it is ignored;
this allows us to have a single logical line that spans several lines
5. Keywords
There are around 38 keywords in Ruby.These are reserved and cannot be used for other purposes
Keywords in Ruby
alias
and
BEGIN
begin
break
case
class
def
defined
do
else
elsif
END
end
ensure
false
for
if
in
module
next
nil
not
or
redo
rescue
retry
return
self
super
then
true
undef
unless
until
when
while
yield
Note : False and Nil are reserved words in Ruby....so they can't be used as(Zero)