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

PDF
Spring boot jpa
PPT
Workin ontherailsroad
PPT
WorkinOnTheRailsRoad
ODP
Introduction to Scala
DOCX
Page List & Sample Material (Repaired)
PPTX
What’s new in java 8
PPT
C#3.0 & Vb 9.0 New Features
Spring boot jpa
Workin ontherailsroad
WorkinOnTheRailsRoad
Introduction to Scala
Page List & Sample Material (Repaired)
What’s new in java 8
C#3.0 & Vb 9.0 New Features

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

PPTX
Java features
PPTX
Lambda Expressions Java 8 Features usage
PPTX
Intro to Scala
PPTX
Metaprogramming in Ruby
PPT
Ruby on rails
PPTX
Java script basics
PDF
New c sharp3_features_(linq)_part_ii
PDF
Functional programming in java 8 by harmeet singh
PPT
chap04.ppt
KEY
Ruby on Rails Training - Module 1
KEY
Introduction to Ruby
PDF
Lambda: A Peek Under The Hood - Brian Goetz
PPTX
Python Programming Basics for begginners
PDF
03. Ruby Variables & Regex - Ruby Core Teaching
PPTX
Object oriented Programming for CSE, IT,
PDF
Important JavaScript Concepts Every Developer Must Know
PPTX
Functional Programming In Jdk8
PPT
Rubyforjavaprogrammers 1210167973516759-9
PPT
Rubyforjavaprogrammers 1210167973516759-9
Java features
Lambda Expressions Java 8 Features usage
Intro to Scala
Metaprogramming in Ruby
Ruby on rails
Java script basics
New c sharp3_features_(linq)_part_ii
Functional programming in java 8 by harmeet singh
chap04.ppt
Ruby on Rails Training - Module 1
Introduction to Ruby
Lambda: A Peek Under The Hood - Brian Goetz
Python Programming Basics for begginners
03. Ruby Variables & Regex - Ruby Core Teaching
Object oriented Programming for CSE, IT,
Important JavaScript Concepts Every Developer Must Know
Functional Programming In Jdk8
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9
Ad

More from quanhoangd129 (7)

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

Recently uploaded (20)

PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Essential Infomation Tech presentation.pptx
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
AI in Product Development-omnex systems
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
ai tools demonstartion for schools and inter college
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
history of c programming in notes for students .pptx
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PTS Company Brochure 2025 (1).pdf.......
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Understanding Forklifts - TECH EHS Solution
Essential Infomation Tech presentation.pptx
Odoo POS Development Services by CandidRoot Solutions
CHAPTER 2 - PM Management and IT Context
AI in Product Development-omnex systems
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
ai tools demonstartion for schools and inter college
Navsoft: AI-Powered Business Solutions & Custom Software Development
Odoo Companies in India – Driving Business Transformation.pdf
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Design an Analysis of Algorithms I-SECS-1021-03
history of c programming in notes for students .pptx
How to Choose the Right IT Partner for Your Business in Malaysia
Design an Analysis of Algorithms II-SECS-1021-03

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/