Ruby
-
Upload
alaa-afifi -
Category
Technology
-
view
189 -
download
1
description
Transcript of Ruby
![Page 1: Ruby](https://reader036.fdocuments.us/reader036/viewer/2022082811/558fcfe81a28ab391b8b4620/html5/thumbnails/1.jpg)
Alaa Afifi kamal
Faculty of computers and information cairo university
Vice head to social at fci student union
Participant at NYU Abu Dhabi Hackathon
Intern at imagine cup university (microsoft)
Social media member st scci
FR member at Fekra
![Page 2: Ruby](https://reader036.fdocuments.us/reader036/viewer/2022082811/558fcfe81a28ab391b8b4620/html5/thumbnails/2.jpg)
Introduction to Ruby
![Page 3: Ruby](https://reader036.fdocuments.us/reader036/viewer/2022082811/558fcfe81a28ab391b8b4620/html5/thumbnails/3.jpg)
Ruby
Ruby is a powerful, flexible programming language you can use in web/Internet development, to process text, to create games, and as part of the popular Ruby on Rails web framework. Ruby is:
High-level, meaning reading and writing Ruby is really easy—it looks a lot like regular English!
Interpreted, meaning you don't need a compiler to write and run Ruby. You can write it here at Codecademy or even on your own computer (many are shipped with the Ruby interpreter built in—we'll get to the interpreter later in this lesson).
Object-oriented, meaning it allows users to manipulate data structures called objects in order to build and execute programs. We'll learn more about objects later, but for now, all you need to know is everything in Ruby is an object.
Easy to use. Ruby was designed by Yukihiro Matsumoto (often just called "Matz") in 1995. Matz set out to design a language that emphasized human needs over those of the computer, which is why Ruby is so easy to pick up.
![Page 4: Ruby](https://reader036.fdocuments.us/reader036/viewer/2022082811/558fcfe81a28ab391b8b4620/html5/thumbnails/4.jpg)
Ruby
Outline :
Data taypes(numbers,Booleans and string)
Operators
(Puts,print)
Strings
Single _line comments
Multi_line comments
![Page 5: Ruby](https://reader036.fdocuments.us/reader036/viewer/2022082811/558fcfe81a28ab391b8b4620/html5/thumbnails/5.jpg)
Data types
Numbers is a data tybe at Ruby to define numbers just
My _num=25
Booleans is a data tybe at Ruby to define Booleans just
My_bool=true or false just
string is a data tybe at Ruby to define strings just
My_string=“Ruby”
![Page 6: Ruby](https://reader036.fdocuments.us/reader036/viewer/2022082811/558fcfe81a28ab391b8b4620/html5/thumbnails/6.jpg)
operators
Addition(+) ,subtraction(-),multiplication(*),Division(/),Exponentiation(**) and
module(%)
Exponentiation(**) is used to get the power of the number
Ex: 2 x 2 x 2 =2**3=8 .
module(%) is used to get the remainder of division
Ex: 20%3= 2
How to write it as a code?
My_num=4+4
Output= 8
![Page 7: Ruby](https://reader036.fdocuments.us/reader036/viewer/2022082811/558fcfe81a28ab391b8b4620/html5/thumbnails/7.jpg)
(Puts,print)
The print command just takes whatever you give it and prints it in the screen.
Puts it adds a new (blank) line after the things you want it to print
Ex: puts”Hello”
print”Ruby”
![Page 8: Ruby](https://reader036.fdocuments.us/reader036/viewer/2022082811/558fcfe81a28ab391b8b4620/html5/thumbnails/8.jpg)
stringsLength:
if you want to get the legth of string do that
Ex: “Ruby”.length
output= 4
reverse:
this method help us to sort a list of values
Ex: “Ruby”.reverse
output= ybuR
![Page 9: Ruby](https://reader036.fdocuments.us/reader036/viewer/2022082811/558fcfe81a28ab391b8b4620/html5/thumbnails/9.jpg)
Downcase and upcase methods convert a string ALL UPPER CASE
or lower case
to use upcase or downcase
EX: puts”ruby”.upcase
the output: RUBY
Ex: puts”RUBY”.downcase
the output: ruby
![Page 10: Ruby](https://reader036.fdocuments.us/reader036/viewer/2022082811/558fcfe81a28ab391b8b4620/html5/thumbnails/10.jpg)
Single _line comments
A comment is a bit of text that Ruby won't try to run as code: it's just for
humans to read. Writing good comments not only clarifies your code for other
people who may read it, but helps remind you of what you were doing when
you wrote the code days, months, or even years earlier.
we use # to write a comment
Ex: “ I love Ruby”.length # this line return the length
![Page 11: Ruby](https://reader036.fdocuments.us/reader036/viewer/2022082811/558fcfe81a28ab391b8b4620/html5/thumbnails/11.jpg)
Multi_line comments
You can write a comment that spans multiple lines by starting
each line with a # , but there's an easier way.
if you start with =begin and end with =end ,
everything between those two expressions will be a comment.
Ex:
=begin
I love ruby
it’s nice
=end
![Page 12: Ruby](https://reader036.fdocuments.us/reader036/viewer/2022082811/558fcfe81a28ab391b8b4620/html5/thumbnails/12.jpg)
Thank you
Copyrights to:Alaa Afifi