SlideShare a Scribd company logo
RUBY
BASIC
Hoang Quan(BlazingRockStorm)
Contents
COMMENT
BLOCK, PROC & LAMBDA
DATA TYPES
VARIABLE
LITERAL
OPERATORS
KEYWORD
Comment
Comment
Use for code notes.
Not translated by interpreter.
NORMAL COMMENT
While comments are typically ignored by Ruby,
special “magic comments” contain directives that
affect how the code is interpreted.
MAGIC COMMENT
02. Ruby Basic slides - Ruby Core Teaching
Variables
Variables
A VARIABLE IS SIMPLY A NAME FOR A VALUE.
VARIABLES ARE CREATED AND VALUES
ASSIGNED TO THEM BY ASSIGNMENT
EXPRESSIONS.
Global variable - $ sign
Instance variable - @ sign
Class variable - @@ sign
Local vatiable - no sign
Constants - Capital letters
KINDS OF VARIABLES:
Global Variable
Instance Variables
Class Variables
Local Variable
Constant
Literal
Literal
Block, Proc & Lambda
Block, Proc & Lambda
A very important concept that most of Ruby programmers
misunderstand(including the slides maker!)
The only ones that definitely understand the concept are the Ruby
committers and Rails committers!
Block
A way to group lines of code together
Blocks are enclosed in a do / end statement or between brackets {},
and they can have multiple arguments.
Syntax
Including conditional statement:
Block
Yield is a Ruby keyword that calls a block when you use it.
When you use the yield keyword, the code inside the block will run &
do its work.
Block
Widely used in Ruby more than Proc and Lambda
Advantages
Simple, easy to use
Disadvantages
One time use only (New block must be generated when input
changed)
Leads to code duplication
Proc
Proc is an object that should be stored in a variable
Proc is essentially just a named block to be reuse multiple times
→ Overcome the disadvantages of block
Lambda
Lambda is a function with no specific name
Object of Proc class
Return a value
Used to assign a piece of code
Syntax:
Example:
Lambda
Object of Proc class, so when using, use call:
Operators
! + - ~ * ** / %
<< >> & | ^
== === != <=> >= >
< <= = %= /= -=
+= *= **= .. ... not
and or ?: && ||
Operators
Keyword
Keyword
Priority words in Ruby
Usually used as commands to perform an action
When set name for variable, do not match the keyword name
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 recuse retry return self super
then true undef unless until when
while yield
Keyword
Data type
Data type
Boolean
Symbol
Integer, Float, Rational Number
Nil value: A singleton object of a NilClass. Represents the
absence of value.(In other programming languages, it is a null)
String
Arrays and Hashes
Read more in the https://ruby-doc.org/
Thank you!
ありがとうございます!

More Related Content

What's hot (17)

Hexagonal architecture: how, why and when
Hexagonal architecture: how, why and when
Xoubaman
 
Spring boot
Spring boot
Bhagwat Kumar
 
From Java 11 to 17 and beyond.pdf
From Java 11 to 17 and beyond.pdf
José Paumard
 
Code review
Code review
dqpi
 
DevDay2017 ESGI Essential DDD
DevDay2017 ESGI Essential DDD
Gregory Boissinot
 
How to successfully grow a code review culture
How to successfully grow a code review culture
Nina Zakharenko
 
gRPC - uma breve introdução.pdf
gRPC - uma breve introdução.pdf
Matheus Donizete
 
Object Oriented Javascript
Object Oriented Javascript
NexThoughts Technologies
 
Memory Management in the Java Virtual Machine(Garbage collection)
Memory Management in the Java Virtual Machine(Garbage collection)
Prashanth Kumar
 
Reportes en java con i report y netbeans
Reportes en java con i report y netbeans
hernanluis
 
Quarkus k8s
Quarkus k8s
Georgios Andrianakis
 
Corel guia rápido cdgs2017 quick-start-guide-br
Corel guia rápido cdgs2017 quick-start-guide-br
Sandoval Barros
 
GraalVM
GraalVM
NexThoughts Technologies
 
SOA & WebLogic - Lift & Shift to the Cloud
SOA & WebLogic - Lift & Shift to the Cloud
Simon Haslam
 
Ros platform overview
Ros platform overview
Pablo Iñigo Blasco
 
gRPC on .NET Core - NDC Sydney 2019
gRPC on .NET Core - NDC Sydney 2019
James Newton-King
 
Golang workshop
Golang workshop
Victor S. Recio
 
Hexagonal architecture: how, why and when
Hexagonal architecture: how, why and when
Xoubaman
 
From Java 11 to 17 and beyond.pdf
From Java 11 to 17 and beyond.pdf
José Paumard
 
Code review
Code review
dqpi
 
DevDay2017 ESGI Essential DDD
DevDay2017 ESGI Essential DDD
Gregory Boissinot
 
How to successfully grow a code review culture
How to successfully grow a code review culture
Nina Zakharenko
 
gRPC - uma breve introdução.pdf
gRPC - uma breve introdução.pdf
Matheus Donizete
 
Memory Management in the Java Virtual Machine(Garbage collection)
Memory Management in the Java Virtual Machine(Garbage collection)
Prashanth Kumar
 
Reportes en java con i report y netbeans
Reportes en java con i report y netbeans
hernanluis
 
Corel guia rápido cdgs2017 quick-start-guide-br
Corel guia rápido cdgs2017 quick-start-guide-br
Sandoval Barros
 
SOA & WebLogic - Lift & Shift to the Cloud
SOA & WebLogic - Lift & Shift to the Cloud
Simon Haslam
 
gRPC on .NET Core - NDC Sydney 2019
gRPC on .NET Core - NDC Sydney 2019
James Newton-King
 

Similar to 02. Ruby Basic slides - Ruby Core Teaching (20)

Ruby_Basic
Ruby_Basic
Kushal Jangid
 
Ruby basics
Ruby basics
Tushar Pal
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9
sagaroceanic11
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9
sagaroceanic11
 
Introduction to ruby
Introduction to ruby
Andrew Liu
 
Ruby Interview Questions
Ruby Interview Questions
Sumanth krishna
 
03. Ruby Variables & Regex - Ruby Core Teaching
03. Ruby Variables & Regex - Ruby Core Teaching
quanhoangd129
 
learn Ruby at ASIT
learn Ruby at ASIT
ASIT
 
learn Ruby in AMC Square learning
learn Ruby in AMC Square learning
ASIT Education
 
The ruby programming language
The ruby programming language
praveen0202
 
12 ruby blocks
12 ruby blocks
Walker Maidana
 
Ruby
Ruby
krupasuthar
 
Learn Ruby 2011 - Session 2
Learn Ruby 2011 - Session 2
James Thompson
 
Ruby basics ||
Ruby basics ||
datt30
 
Ruby_Basic.pptx
Ruby_Basic.pptx
Mohammad Junaid Khan
 
7 Methods and Functional Programming
7 Methods and Functional Programming
Deepak Hagadur Bheemaraju
 
06 ruby variables
06 ruby variables
Walker Maidana
 
Eloquent ruby
Eloquent ruby
Santu Koley
 
Workin On The Rails Road
Workin On The Rails Road
RubyOnRails_dude
 
Metaprogramming in Ruby
Metaprogramming in Ruby
Volodymyr Byno
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9
sagaroceanic11
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9
sagaroceanic11
 
Introduction to ruby
Introduction to ruby
Andrew Liu
 
Ruby Interview Questions
Ruby Interview Questions
Sumanth krishna
 
03. Ruby Variables & Regex - Ruby Core Teaching
03. Ruby Variables & Regex - Ruby Core Teaching
quanhoangd129
 
learn Ruby at ASIT
learn Ruby at ASIT
ASIT
 
learn Ruby in AMC Square learning
learn Ruby in AMC Square learning
ASIT Education
 
The ruby programming language
The ruby programming language
praveen0202
 
Learn Ruby 2011 - Session 2
Learn Ruby 2011 - Session 2
James Thompson
 
Ruby basics ||
Ruby basics ||
datt30
 
Metaprogramming in Ruby
Metaprogramming in Ruby
Volodymyr Byno
 
Ad

More from quanhoangd129 (6)

09. Ruby Object Oriented Programming - Ruby Core Teaching
09. Ruby Object Oriented Programming - Ruby Core Teaching
quanhoangd129
 
07. Ruby String Slides - Ruby Core Teaching
07. Ruby String Slides - Ruby Core Teaching
quanhoangd129
 
06. Ruby Array & Hash - Ruby Core Teaching
06. Ruby Array & Hash - Ruby Core Teaching
quanhoangd129
 
05. Ruby Control Structures - Ruby Core Teaching
05. Ruby Control Structures - Ruby Core Teaching
quanhoangd129
 
04. Ruby Operators Slides - Ruby Core Teaching
04. Ruby Operators Slides - Ruby Core Teaching
quanhoangd129
 
08. Ruby Enumerable - Ruby Core Teaching
08. Ruby Enumerable - Ruby Core Teaching
quanhoangd129
 
09. Ruby Object Oriented Programming - Ruby Core Teaching
09. Ruby Object Oriented Programming - Ruby Core Teaching
quanhoangd129
 
07. Ruby String Slides - Ruby Core Teaching
07. Ruby String Slides - Ruby Core Teaching
quanhoangd129
 
06. Ruby Array & Hash - Ruby Core Teaching
06. Ruby Array & Hash - Ruby Core Teaching
quanhoangd129
 
05. Ruby Control Structures - Ruby Core Teaching
05. Ruby Control Structures - Ruby Core Teaching
quanhoangd129
 
04. Ruby Operators Slides - Ruby Core Teaching
04. Ruby Operators Slides - Ruby Core Teaching
quanhoangd129
 
08. Ruby Enumerable - Ruby Core Teaching
08. Ruby Enumerable - Ruby Core Teaching
quanhoangd129
 
Ad

Recently uploaded (20)

How to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdf
Creative Fosters
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
AI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA Technologies
SandeepKS52
 
Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3
Gaurav Sharma
 
Advanced Token Development - Decentralized Innovation
Advanced Token Development - Decentralized Innovation
arohisinghas720
 
Reimagining Software Development and DevOps with Agentic AI
Reimagining Software Development and DevOps with Agentic AI
Maxim Salnikov
 
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
BradBedford3
 
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
 
What is data visualization and how data visualization tool can help.pdf
What is data visualization and how data visualization tool can help.pdf
Varsha Nayak
 
Porting Qt 5 QML Modules to Qt 6 Webinar
Porting Qt 5 QML Modules to Qt 6 Webinar
ICS
 
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Transmission Media. (Computer Networks)
Transmission Media. (Computer Networks)
S Pranav (Deepu)
 
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
 
Open Source Software Development Methods
Open Source Software Development Methods
VICTOR MAESTRE RAMIREZ
 
Zoneranker’s Digital marketing solutions
Zoneranker’s Digital marketing solutions
reenashriee
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
How to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdf
Creative Fosters
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
AI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA Technologies
SandeepKS52
 
Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3
Gaurav Sharma
 
Advanced Token Development - Decentralized Innovation
Advanced Token Development - Decentralized Innovation
arohisinghas720
 
Reimagining Software Development and DevOps with Agentic AI
Reimagining Software Development and DevOps with Agentic AI
Maxim Salnikov
 
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
BradBedford3
 
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
 
What is data visualization and how data visualization tool can help.pdf
What is data visualization and how data visualization tool can help.pdf
Varsha Nayak
 
Porting Qt 5 QML Modules to Qt 6 Webinar
Porting Qt 5 QML Modules to Qt 6 Webinar
ICS
 
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Transmission Media. (Computer Networks)
Transmission Media. (Computer Networks)
S Pranav (Deepu)
 
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
 
Open Source Software Development Methods
Open Source Software Development Methods
VICTOR MAESTRE RAMIREZ
 
Zoneranker’s Digital marketing solutions
Zoneranker’s Digital marketing solutions
reenashriee
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 

02. Ruby Basic slides - Ruby Core Teaching

  • 2. Contents COMMENT BLOCK, PROC & LAMBDA DATA TYPES VARIABLE LITERAL OPERATORS KEYWORD
  • 4. Comment Use for code notes. Not translated by interpreter. NORMAL COMMENT While comments are typically ignored by Ruby, special “magic comments” contain directives that affect how the code is interpreted. MAGIC COMMENT
  • 7. Variables A VARIABLE IS SIMPLY A NAME FOR A VALUE. VARIABLES ARE CREATED AND VALUES ASSIGNED TO THEM BY ASSIGNMENT EXPRESSIONS. Global variable - $ sign Instance variable - @ sign Class variable - @@ sign Local vatiable - no sign Constants - Capital letters KINDS OF VARIABLES:
  • 15. Block, Proc & Lambda
  • 16. Block, Proc & Lambda A very important concept that most of Ruby programmers misunderstand(including the slides maker!) The only ones that definitely understand the concept are the Ruby committers and Rails committers!
  • 17. Block A way to group lines of code together Blocks are enclosed in a do / end statement or between brackets {}, and they can have multiple arguments. Syntax Including conditional statement:
  • 18. Block Yield is a Ruby keyword that calls a block when you use it. When you use the yield keyword, the code inside the block will run & do its work.
  • 19. Block Widely used in Ruby more than Proc and Lambda Advantages Simple, easy to use Disadvantages One time use only (New block must be generated when input changed) Leads to code duplication
  • 20. Proc Proc is an object that should be stored in a variable Proc is essentially just a named block to be reuse multiple times → Overcome the disadvantages of block
  • 21. Lambda Lambda is a function with no specific name Object of Proc class Return a value Used to assign a piece of code Syntax: Example:
  • 22. Lambda Object of Proc class, so when using, use call:
  • 24. ! + - ~ * ** / % << >> & | ^ == === != <=> >= > < <= = %= /= -= += *= **= .. ... not and or ?: && || Operators
  • 26. Keyword Priority words in Ruby Usually used as commands to perform an action When set name for variable, do not match the keyword name
  • 27. 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 recuse retry return self super then true undef unless until when while yield Keyword
  • 29. Data type Boolean Symbol Integer, Float, Rational Number Nil value: A singleton object of a NilClass. Represents the absence of value.(In other programming languages, it is a null) String Arrays and Hashes Read more in the https://ruby-doc.org/