DEV Community

salcasta
salcasta

Posted on

Ruby Basics - Intro

Let us recap the basics of Ruby in Codecademy!

Ruby takes strings, booleans, and numbers as variables

my_num =  25  
my_boolean = true   
my_string = "Ruby"  
Enter fullscreen mode Exit fullscreen mode

Variables are declared as with a variable name and equal sign

my_num = 100
Enter fullscreen mode Exit fullscreen mode

Ruby allows for all mathematical symbols ...
Addition (+)
Subtraction (-)
Multiplication ()
Division (/)
Exponentiation (
*)
Modulo (%) => remainder

Puts and Print

Print - prints it to the screen
puts - adds a blank line and then puts the variable

Popular Methods

.length => number of characters in a string
.reverse
.upcase
.downcase

How to comment

single line comment uses => #

multi line comment ...

#
=begin
hello
this 
is
just
comments
=end
Enter fullscreen mode Exit fullscreen mode

Multiple words in a variable name is ok as long as you use an underscore in between words

this_is_my_long_variable =

Getting an input from the user

Ask a question and then set a prompt using gets.chomp

print "What is your last name? "
last_name = gets.chomp

#Use methods to get the the user input in the correct format 

ex. last_name.capitalize!
Enter fullscreen mode Exit fullscreen mode

Top comments (0)