Sitemap
2 min readSep 19, 2022

--

Ruby Basics

Why should you learn Ruby ?

It’s built for developers to program easily. In other word, it is built for human so it’s a friendlier language. It can be used as a procedural, functional or object-oriented language. Everything in Ruby is object. Ruby is powerful at building dictionary like application such as e-commerce or listing movies. Ruby can be used for database work, system utilities, backups, parsing, biology, medicine, web applications and web servers. Below is a list of companies that use Ruby.

AirbnbShopifyNetflixGithubGrouponHulu

What is the purpose of Application Programming Interface, API?

It’s the middleman between the database and the application. We use API to access certain data that we want to integrate into our application and the data is up to how the API is built, depending on what types of accessibilities we have. Think of API as a restaurant waiting staff and database as food that you receive as a customer.

Method

Method is like function in JS.

def init
puts "hello"
end

Puts vs print

puts: print with a line break 
hello
world
print: omit the line break / same line
hello world

Return value

last line of method will be return value

binding.pry

It is like debugger in JS to access variables or functions at the particular code line.

execute this code by ruby bin/run then in the

Get Greem’s stories in your inbox

Join Medium for free to get updates from this writer.

quit to quit

It only has access to the specific scope.

exit! to completely exit

String Interpolation

    name = gets
puts "Hello #{name}"

While / until loop

until selection == 'exit'
while selection != 'exit'

Configuration

If our environment isn’t configured yet, we need `bin/run` file to direct the configuration

#bin/run#!/usr/bin/env rubyrequire_relative "../config/environment"init

bundle install all the gem

bundle install

Run below command in the terminal

$ruby bin/run
$./bin/run

--

--