![]() |
Ruby is a pure Object-Oriented language developed by Yukihiro Matsumoto (also known as Matz in the Ruby community) in the mid 1990’s in Japan. To program in Ruby is easy to learn because of its similar syntax to already widely used languages. Here, we will learn the basic syntax of Ruby language.
Output: Hello World! End of a line in RubyRuby interprets newline characters(\n) and semicolons(;) as the end of a statement. Whitespace in RubyWhitespace characters such as spaces and tabs are generally ignored in Ruby code, except when they appear in a string, i.e. it ignores all spaces in a statement But sometimes, whitespaces are used to interpret ambiguous statements.
Output: 5 1 Ruby BEGIN and END statementBEGIN statement is used to declare a part of code which must be called before the program runs. Syntax: BEGIN { # code written here } Similarly, END is used to declare a part of code which must be called at the end of program. END { # code written here } Example of BEGIN and END
Output: BEGINNING of the Program This is main body of program Ruby commentsA comment hides some part of code, from the Ruby Interpreter. Comments can be written in different ways, using hash character(#) at the beginning of a line. #This is a single line comment #This is multiple #lines of comment =begin This is another way of writing comments in a block fashion =end Identifiers in Ruby
For example: Man_1, item_01 are examples of identifiers. Keywords in RubyThe reserved words in Ruby which cannot be used as constant or variable names are called keywords of Ruby.
|
Reffered: https://www.geeksforgeeks.org
Ruby |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 8 |