SlideShare a Scribd company logo
 Ruby is a pure object-oriented programming
language.
 It was created by Yukihiro Matsumoto of Japan.
 Ruby is a server-side scripting language, which
can be embedded into HTML.
 All ruby files will have extension .rb. To run ruby
programs use ruby file_name.rb.
 For single-line comment you can use the hash character
(#) at the beginning of a line. For multi-line
=begin/=end.
 Ruby interprets semicolons and newline characters as
the ending of a statement.
 Following a << you can specify a string or an identifier
to terminate the string literal.
 BEGIN – Declares code to be called before the
program is run.
BEGIN
{
code
}
 END – Declares code to be called at the end of the
program.
END
{
code
}
 Local variables: Local variables are the
variables that are defined in a method.
 Instance variables: Instance variables are
available across methods for any particular
instance or object. That means that instance
variables change from object to object. Instance
variables are preceded by the at sign (@)
followed by the variable name.
 Class variables: A class variable belongs to the
class and is a characteristic of a class. They are
preceded by the sign @@ and are followed by
the variable name.
 Global variables: A global variable can
available across classes. The global variables are
always preceded by $ sign.
 Numbers
 Strings
 Symbols
 Hashes
 Arrays
 Booleans
if...else Statement
if conditional [then]
code...
[else
code...]
end
else...if Statement
if conditional [then]
code...
[elsif conditional [then]
code...]...
[else
code...]
end
if modifier
code if condition
unless modifier
code unless condition
unless Statement
unless conditional [then]
code
[else
code ]
end
case Statement
case expression
[when expression [, expression ...] [then]
code ]...
[else
code ]
end
while Statement
while conditional [do]
code
end
until Statement
until conditional [do]
code
end
while Modifier
code while condition
or
begin
code
end while condition
until Modifier
code until condition
or
begin
code
end until condition
for Statement
for variable [, variable ...] in expression [do]
code
end
(expression).each do |variable[, variable...]|
code
end
gets
 gets is used to read from the user and store in
string form.
 to_i is used convert string to integer and to_f is
used to convert string to float.
puts
 puts is used to display a string on the output
screen.
print
 print is also used to display a string or a variable
value on the output screen.
 Ruby arrays are ordered collections of any object.
Creating Arrays
 There are many ways to create or initialize an
array.
 var = Array.new or var = Array.new(size)
 var = Array.[](value1,value2,….) or
var = Array[value1,value2,….] or
var = [val1,val2,…]
 array.at(index)
 array.clear
 arrray.delete(obj)
 array.delete_at(index)
 array.empty?
 array.index(obj)
 array.insert(index,obj)
 array.join(sep)
 array.length
 array.pop
 array.push(objs)
 arr.reverse!
 A hash is a collection of key-value pairs.
Creating Hashes:
 var_name = Hash.new()
 var_name = Hash.new(obj)
 var_name = Hash[key1=>value1,key2=>value2…]
 var_name = {key1=>value1,key2=>value2…}
 hash.clear
 hash.delete(key)
 hash.empty?
 hash.fetch(key[,default])
 hash.has_key?(key)
 hash.has_value?(value)
 hash.invert
 hash.keys
 hash.length
 hash.merge(other_hash) or hash.merge!(other_hash)
 hash.values
 Ruby methods are used to bundle one or more repeatable
statements into a single unit.
Syntax:
def method_name [( [arg [= default]]...[, * arg [, &expr ]])]
#method_body
end
return
 return statement is used to return one or more values from a
method
Syntax:
return [expr[, expr...]]
 A class is a collection of data members and member functions.
Syntax:
class class_name
@@class_variables
def initialize()
@instance_variables
end
def function_name
statements
end
end
Creating Object:
obj = class_name.new
 Iterators are nothing but methods supported by
collections. Objects that store a group of data members
are called collections.
Syntax:
collection.each do |variable|
code
end
 The collect iterator returns all the elements of a collection.
Syntax:
collection2 = collection1.collect

More Related Content

What's hot

String Interpolation in Scala
String Interpolation in ScalaString Interpolation in Scala
String Interpolation in Scala
Knoldus Inc.
 
Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2
Manoj Ellappan
 
Strings in c
Strings in cStrings in c
Strings in c
vampugani
 
2 variables and data types
2   variables and data types2   variables and data types
2 variables and data types
Tuan Ngo
 
JavaScript Data Types
JavaScript Data TypesJavaScript Data Types
JavaScript Data Types
Charles Russell
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
Rai University
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
Neeru Mittal
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
Pranali Chaudhari
 
Compiler: Programming Language= Assignments and statements
Compiler: Programming Language= Assignments and statementsCompiler: Programming Language= Assignments and statements
Compiler: Programming Language= Assignments and statements
Geo Marian
 
Swift Study #3
Swift Study #3Swift Study #3
Swift Study #3
chanju Jeon
 
Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
Javascript
JavascriptJavascript
Javascript
guest03a6e6
 
DIWE - Advanced PHP Concepts
DIWE - Advanced PHP ConceptsDIWE - Advanced PHP Concepts
DIWE - Advanced PHP Concepts
Rasan Samarasinghe
 
Pattern Matching - at a glance
Pattern Matching - at a glancePattern Matching - at a glance
Pattern Matching - at a glance
Knoldus Inc.
 
ASSIGNMENT STATEMENTS AND
ASSIGNMENT STATEMENTS ANDASSIGNMENT STATEMENTS AND
ASSIGNMENT STATEMENTS AND
Damith Shan Abeywickrema
 
String c
String cString c
Learn ActionScript programming myassignmenthelp.net
Learn ActionScript programming myassignmenthelp.netLearn ActionScript programming myassignmenthelp.net
Learn ActionScript programming myassignmenthelp.net
www.myassignmenthelp.net
 
String C Programming
String C ProgrammingString C Programming
String C Programming
Prionto Abdullah
 
String in c programming
String in c programmingString in c programming
String in c programming
Devan Thakur
 
String in c
String in cString in c
String in c
Suneel Dogra
 

What's hot (20)

String Interpolation in Scala
String Interpolation in ScalaString Interpolation in Scala
String Interpolation in Scala
 
Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2
 
Strings in c
Strings in cStrings in c
Strings in c
 
2 variables and data types
2   variables and data types2   variables and data types
2 variables and data types
 
JavaScript Data Types
JavaScript Data TypesJavaScript Data Types
JavaScript Data Types
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
Compiler: Programming Language= Assignments and statements
Compiler: Programming Language= Assignments and statementsCompiler: Programming Language= Assignments and statements
Compiler: Programming Language= Assignments and statements
 
Swift Study #3
Swift Study #3Swift Study #3
Swift Study #3
 
Strings in C
Strings in CStrings in C
Strings in C
 
Javascript
JavascriptJavascript
Javascript
 
DIWE - Advanced PHP Concepts
DIWE - Advanced PHP ConceptsDIWE - Advanced PHP Concepts
DIWE - Advanced PHP Concepts
 
Pattern Matching - at a glance
Pattern Matching - at a glancePattern Matching - at a glance
Pattern Matching - at a glance
 
ASSIGNMENT STATEMENTS AND
ASSIGNMENT STATEMENTS ANDASSIGNMENT STATEMENTS AND
ASSIGNMENT STATEMENTS AND
 
String c
String cString c
String c
 
Learn ActionScript programming myassignmenthelp.net
Learn ActionScript programming myassignmenthelp.netLearn ActionScript programming myassignmenthelp.net
Learn ActionScript programming myassignmenthelp.net
 
String C Programming
String C ProgrammingString C Programming
String C Programming
 
String in c programming
String in c programmingString in c programming
String in c programming
 
String in c
String in cString in c
String in c
 

Similar to Ruby

JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
Govardhan Bhavani
 
Ruby_Basic
Ruby_BasicRuby_Basic
Ruby_Basic
Kushal Jangid
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
Santosh Rajan
 
Perl Basics with Examples
Perl Basics with ExamplesPerl Basics with Examples
Perl Basics with Examples
Nithin Kumar Singani
 
06 ruby variables
06 ruby variables06 ruby variables
06 ruby variables
Walker Maidana
 
Ruby
RubyRuby
Language tour of dart
Language tour of dartLanguage tour of dart
Language tour of dart
Imran Qasim
 
Python Programming Basics for begginners
Python Programming Basics for begginnersPython Programming Basics for begginners
Python Programming Basics for begginners
Abishek Purushothaman
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
Mufaddal Haidermota
 
MMBJ Shanzhai Culture
MMBJ Shanzhai CultureMMBJ Shanzhai Culture
MMBJ Shanzhai Culture
MobileMonday Beijing
 
Washington Practitioners Significant Changes To Rpc 1.5
Washington Practitioners Significant Changes To Rpc 1.5Washington Practitioners Significant Changes To Rpc 1.5
Washington Practitioners Significant Changes To Rpc 1.5
Oregon Law Practice Management
 
Agapornis Mansos - www.criadourosudica.blogspot.com
Agapornis Mansos - www.criadourosudica.blogspot.comAgapornis Mansos - www.criadourosudica.blogspot.com
Agapornis Mansos - www.criadourosudica.blogspot.com
Antonio Silva
 
Paulo Freire Pedagpogia 1
Paulo Freire Pedagpogia 1Paulo Freire Pedagpogia 1
Paulo Freire Pedagpogia 1
Alejandra Perez
 
Jerry Shea Resume And Addendum 5 2 09
Jerry  Shea Resume And Addendum 5 2 09Jerry  Shea Resume And Addendum 5 2 09
Jerry Shea Resume And Addendum 5 2 09
gshea11
 
LoteríA Correcta
LoteríA CorrectaLoteríA Correcta
LoteríA Correcta
guest4dfcdf6
 
Majlis Persaraan Pn.Hjh.Normah bersama guru-guru Sesi Petang
Majlis Persaraan Pn.Hjh.Normah bersama guru-guru Sesi PetangMajlis Persaraan Pn.Hjh.Normah bersama guru-guru Sesi Petang
Majlis Persaraan Pn.Hjh.Normah bersama guru-guru Sesi Petang
Imsamad
 
Ruby data types and objects
Ruby   data types and objectsRuby   data types and objects
Ruby data types and objects
Harkamal Singh
 
Ruby Presentation
Ruby Presentation Ruby Presentation
Ruby Presentation
platico_dev
 
Objective c slide I
Objective c slide IObjective c slide I
Objective c slide I
Diksha Bhargava
 
Variable and constants in Vb.NET
Variable and constants in Vb.NETVariable and constants in Vb.NET
Variable and constants in Vb.NET
Jaya Kumari
 

Similar to Ruby (20)

JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
 
Ruby_Basic
Ruby_BasicRuby_Basic
Ruby_Basic
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
 
Perl Basics with Examples
Perl Basics with ExamplesPerl Basics with Examples
Perl Basics with Examples
 
06 ruby variables
06 ruby variables06 ruby variables
06 ruby variables
 
Ruby
RubyRuby
Ruby
 
Language tour of dart
Language tour of dartLanguage tour of dart
Language tour of dart
 
Python Programming Basics for begginners
Python Programming Basics for begginnersPython Programming Basics for begginners
Python Programming Basics for begginners
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
MMBJ Shanzhai Culture
MMBJ Shanzhai CultureMMBJ Shanzhai Culture
MMBJ Shanzhai Culture
 
Washington Practitioners Significant Changes To Rpc 1.5
Washington Practitioners Significant Changes To Rpc 1.5Washington Practitioners Significant Changes To Rpc 1.5
Washington Practitioners Significant Changes To Rpc 1.5
 
Agapornis Mansos - www.criadourosudica.blogspot.com
Agapornis Mansos - www.criadourosudica.blogspot.comAgapornis Mansos - www.criadourosudica.blogspot.com
Agapornis Mansos - www.criadourosudica.blogspot.com
 
Paulo Freire Pedagpogia 1
Paulo Freire Pedagpogia 1Paulo Freire Pedagpogia 1
Paulo Freire Pedagpogia 1
 
Jerry Shea Resume And Addendum 5 2 09
Jerry  Shea Resume And Addendum 5 2 09Jerry  Shea Resume And Addendum 5 2 09
Jerry Shea Resume And Addendum 5 2 09
 
LoteríA Correcta
LoteríA CorrectaLoteríA Correcta
LoteríA Correcta
 
Majlis Persaraan Pn.Hjh.Normah bersama guru-guru Sesi Petang
Majlis Persaraan Pn.Hjh.Normah bersama guru-guru Sesi PetangMajlis Persaraan Pn.Hjh.Normah bersama guru-guru Sesi Petang
Majlis Persaraan Pn.Hjh.Normah bersama guru-guru Sesi Petang
 
Ruby data types and objects
Ruby   data types and objectsRuby   data types and objects
Ruby data types and objects
 
Ruby Presentation
Ruby Presentation Ruby Presentation
Ruby Presentation
 
Objective c slide I
Objective c slide IObjective c slide I
Objective c slide I
 
Variable and constants in Vb.NET
Variable and constants in Vb.NETVariable and constants in Vb.NET
Variable and constants in Vb.NET
 

More from Govardhan Bhavani

Angular Application Setup.pptx
Angular Application Setup.pptxAngular Application Setup.pptx
Angular Application Setup.pptx
Govardhan Bhavani
 
Files.pptx
Files.pptxFiles.pptx
Files.pptx
Govardhan Bhavani
 
Pandas.pptx
Pandas.pptxPandas.pptx
Pandas.pptx
Govardhan Bhavani
 
NumPy.pptx
NumPy.pptxNumPy.pptx
NumPy.pptx
Govardhan Bhavani
 
ExpressJS and REST API.pptx
ExpressJS and REST API.pptxExpressJS and REST API.pptx
ExpressJS and REST API.pptx
Govardhan Bhavani
 
NodeJS.pptx
NodeJS.pptxNodeJS.pptx
NodeJS.pptx
Govardhan Bhavani
 
Angular.pptx
Angular.pptxAngular.pptx
Angular.pptx
Govardhan Bhavani
 
Maven.pptx
Maven.pptxMaven.pptx
Maven.pptx
Govardhan Bhavani
 
Configure & Version Control-Git.pptx
Configure & Version Control-Git.pptxConfigure & Version Control-Git.pptx
Configure & Version Control-Git.pptx
Govardhan Bhavani
 
DevOps.pptx
DevOps.pptxDevOps.pptx
DevOps.pptx
Govardhan Bhavani
 
Agile XP.pptx
Agile XP.pptxAgile XP.pptx
Agile XP.pptx
Govardhan Bhavani
 
Ajax
AjaxAjax
CSS
CSSCSS
Unit 1part-2 forms & frames
Unit 1part-2 forms & framesUnit 1part-2 forms & frames
Unit 1part-2 forms & frames
Govardhan Bhavani
 
Unit 1 (part-1, basic tags)
Unit 1 (part-1, basic tags)Unit 1 (part-1, basic tags)
Unit 1 (part-1, basic tags)
Govardhan Bhavani
 

More from Govardhan Bhavani (15)

Angular Application Setup.pptx
Angular Application Setup.pptxAngular Application Setup.pptx
Angular Application Setup.pptx
 
Files.pptx
Files.pptxFiles.pptx
Files.pptx
 
Pandas.pptx
Pandas.pptxPandas.pptx
Pandas.pptx
 
NumPy.pptx
NumPy.pptxNumPy.pptx
NumPy.pptx
 
ExpressJS and REST API.pptx
ExpressJS and REST API.pptxExpressJS and REST API.pptx
ExpressJS and REST API.pptx
 
NodeJS.pptx
NodeJS.pptxNodeJS.pptx
NodeJS.pptx
 
Angular.pptx
Angular.pptxAngular.pptx
Angular.pptx
 
Maven.pptx
Maven.pptxMaven.pptx
Maven.pptx
 
Configure & Version Control-Git.pptx
Configure & Version Control-Git.pptxConfigure & Version Control-Git.pptx
Configure & Version Control-Git.pptx
 
DevOps.pptx
DevOps.pptxDevOps.pptx
DevOps.pptx
 
Agile XP.pptx
Agile XP.pptxAgile XP.pptx
Agile XP.pptx
 
Ajax
AjaxAjax
Ajax
 
CSS
CSSCSS
CSS
 
Unit 1part-2 forms & frames
Unit 1part-2 forms & framesUnit 1part-2 forms & frames
Unit 1part-2 forms & frames
 
Unit 1 (part-1, basic tags)
Unit 1 (part-1, basic tags)Unit 1 (part-1, basic tags)
Unit 1 (part-1, basic tags)
 

Recently uploaded

Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
Kavitha Krishnan
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 

Recently uploaded (20)

Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 

Ruby

  • 1.
  • 2.  Ruby is a pure object-oriented programming language.  It was created by Yukihiro Matsumoto of Japan.  Ruby is a server-side scripting language, which can be embedded into HTML.
  • 3.  All ruby files will have extension .rb. To run ruby programs use ruby file_name.rb.  For single-line comment you can use the hash character (#) at the beginning of a line. For multi-line =begin/=end.  Ruby interprets semicolons and newline characters as the ending of a statement.  Following a << you can specify a string or an identifier to terminate the string literal.
  • 4.
  • 5.  BEGIN – Declares code to be called before the program is run. BEGIN { code }  END – Declares code to be called at the end of the program. END { code }
  • 6.  Local variables: Local variables are the variables that are defined in a method.  Instance variables: Instance variables are available across methods for any particular instance or object. That means that instance variables change from object to object. Instance variables are preceded by the at sign (@) followed by the variable name.
  • 7.  Class variables: A class variable belongs to the class and is a characteristic of a class. They are preceded by the sign @@ and are followed by the variable name.  Global variables: A global variable can available across classes. The global variables are always preceded by $ sign.
  • 8.  Numbers  Strings  Symbols  Hashes  Arrays  Booleans
  • 9. if...else Statement if conditional [then] code... [else code...] end else...if Statement if conditional [then] code... [elsif conditional [then] code...]... [else code...] end
  • 10. if modifier code if condition unless modifier code unless condition unless Statement unless conditional [then] code [else code ] end
  • 11. case Statement case expression [when expression [, expression ...] [then] code ]... [else code ] end
  • 12. while Statement while conditional [do] code end until Statement until conditional [do] code end
  • 13. while Modifier code while condition or begin code end while condition until Modifier code until condition or begin code end until condition
  • 14. for Statement for variable [, variable ...] in expression [do] code end (expression).each do |variable[, variable...]| code end
  • 15. gets  gets is used to read from the user and store in string form.  to_i is used convert string to integer and to_f is used to convert string to float. puts  puts is used to display a string on the output screen. print  print is also used to display a string or a variable value on the output screen.
  • 16.  Ruby arrays are ordered collections of any object. Creating Arrays  There are many ways to create or initialize an array.  var = Array.new or var = Array.new(size)  var = Array.[](value1,value2,….) or var = Array[value1,value2,….] or var = [val1,val2,…]
  • 17.  array.at(index)  array.clear  arrray.delete(obj)  array.delete_at(index)  array.empty?  array.index(obj)  array.insert(index,obj)  array.join(sep)  array.length  array.pop  array.push(objs)  arr.reverse!
  • 18.  A hash is a collection of key-value pairs. Creating Hashes:  var_name = Hash.new()  var_name = Hash.new(obj)  var_name = Hash[key1=>value1,key2=>value2…]  var_name = {key1=>value1,key2=>value2…}
  • 19.  hash.clear  hash.delete(key)  hash.empty?  hash.fetch(key[,default])  hash.has_key?(key)  hash.has_value?(value)  hash.invert  hash.keys  hash.length  hash.merge(other_hash) or hash.merge!(other_hash)  hash.values
  • 20.  Ruby methods are used to bundle one or more repeatable statements into a single unit. Syntax: def method_name [( [arg [= default]]...[, * arg [, &expr ]])] #method_body end return  return statement is used to return one or more values from a method Syntax: return [expr[, expr...]]
  • 21.  A class is a collection of data members and member functions. Syntax: class class_name @@class_variables def initialize() @instance_variables end def function_name statements end end Creating Object: obj = class_name.new
  • 22.  Iterators are nothing but methods supported by collections. Objects that store a group of data members are called collections. Syntax: collection.each do |variable| code end  The collect iterator returns all the elements of a collection. Syntax: collection2 = collection1.collect