0% found this document useful (0 votes)
7 views

Programming For Everybody: 1. Intro To Ruby

The document introduces programming concepts in Ruby including printing, data types, variables, math operations, built-in methods, commenting, string interpolation, and user input. Printing is done with print or puts. Common data types are strings, numbers, and booleans. Variables are used to store and reference values. Basic math operations and built-in methods are covered.

Uploaded by

sal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Programming For Everybody: 1. Intro To Ruby

The document introduces programming concepts in Ruby including printing, data types, variables, math operations, built-in methods, commenting, string interpolation, and user input. Printing is done with print or puts. Common data types are strings, numbers, and booleans. Variables are used to store and reference values. Basic math operations and built-in methods are covered.

Uploaded by

sal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Programming for

Everybody

1. Intro to Ruby
Puts & Prints
Two commands we use to print info to the
console

PRINT
prints to the console whatever you give it

PUTS
prints to the console whatever you give it and
adds a new blank line below
Data Types
1. STRINGS
words or sentences
always go within “ “

2. NUMBERS
integers (whole numbers) and floats (decimal numbers)
shouldn’t be wrapped with “ “

3. BOOLEANS
true or false
shouldn’t be wrapped with “ “
Variables
A word to which we assign a certain content (string,
number, boolean)

We set it and it it remains there, ready for future use

Naming a variable: always small letters with words


separated by _ (ex: my_name)

Assigning a value to a variable: we use the = sign


(ex: my_name = “Mariana”)
Math
With Ruby we can perform the following math operations:

Addition +
Subtraction -
Multiplication *
Division /
Exponentiation **
Modulo %
Built in methods
“Special behaviour” Ruby data has that we can summon

We call methods with a . plus the method name

https://ruby-doc.org/core-2.5.3/Method.html

The ! after a method changes the content of the original


variable for good
Commenting out in Ruby

SINGLE LINE COMMENTS


#I’m a single line comment

MULTIPLE LINE COMMENTS


=begin
I’m a multiple line
comment
=end
String interpolation

name = “Mariana”

puts “My name is #{name}”

result -> My name is Mariana


Gets & Chomps

GETS
Gets input from the user and ads a blank line after each input

CHOMP
Removes that extra line
Thank you! :)

You might also like