This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Everything's ok | |
200 - OK | |
# Redirects or cache | |
301 - Permanent redirect | |
302 - Temp redirect | |
304 - Not modified | |
# Client error (you screw up) | |
401 - Unauthorized |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def beautify_name(first_name, last_name) | |
full_name = "#{first_name.capitalize} #{last_name.upcase}" | |
yield(full_name) | |
end | |
message = beautify_name("john", "lennon") do |name| | |
"Greetings #{name}, you look quite fine today!" | |
end | |
message = beautify_name("john", "lennon") do |name| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
paris = { | |
"country" => "France", | |
"population" => 2211000 | |
} | |
students = { | |
2882 => { | |
'name' => 'Ricardo', | |
'age' => 27 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# car.rb | |
# filename - lower_snake_case | |
# class name - UpperCamelCase | |
# sports_car.rb => SportsCar | |
class Car | |
attr_reader :brand | |
# attr_writer :color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# chef.rb | |
class Chef | |
attr_reader :name, :restaurant | |
def initialize(name, restaurant) | |
@name = name # String instance | |
@restaurant = restaurant # Restaurant instance | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# methods.rb | |
# method names should be snake_cased | |
# no arguments | |
def random_method | |
return 10 | |
end | |
# puts random_method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# car.rb | |
class Car | |
# attr_reader :color, :brand | |
attr_reader :brand | |
# attr_writer :color | |
attr_accessor :color | |
# initializer or constructor | |
def initialize(color, brand) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Citizen | |
# attr_reader :first_name, :last_name, :age | |
attr_reader :age, :height | |
def initialize(first_name, last_name) | |
@first_name = first_name | |
@last_name = last_name | |
@age = 0 | |
@height = rand(10..40) | |
@alive = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# chef.rb | |
class Chef | |
attr_reader :name, :restaurant | |
def initialize(name, restaurant) | |
@name = name # String instance | |
@restaurant = restaurant # Restaurant instance | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# controller.rb | |
require_relative 'view' | |
require_relative 'task' | |
class Controller | |
def initialize(repository) | |
@repo = repository | |
@view = View.new | |
end |