This file contains hidden or 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
require 'date' | |
require 'yaml' | |
PATTERN = /^(?<gender>[12])\s?(?<yob>\d{2})\s?(?<mob>0[1-9]|1[0-2])\s?(?<department>\d\d|2[AB])\s?\d{3}\s?\d{3}\s?(?<key>\d\d)$/ | |
# hash | |
DEPARTMENTS = YAML.load_file('./data/french_departments.yml') | |
def french_ssn(ssn) | |
return "The number is invalid" if ssn.empty? |
This file contains hidden or 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
# Player begins with 100$ | |
# if player wins 50$ | |
# otherwise loses 10$ | |
# player = { wallet: 100 } | |
# list of a horses / race roster => Array | |
# ==== START LOOP ==== | |
# display list of horses | |
# ask the user for the winning horse | |
# store user choice |
This file contains hidden or 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 acronymize(sentence) | |
# map => [] | |
# applies transformations to elements | |
# 1. split sentence into words (list use Array) | |
words = sentence.split | |
# 2. Go through/Take each word | |
# and take/grab the first letter (capitalize) | |
initials = words.map { |word| word[0].capitalize } | |
# 3. Join words into a single sentence |
This file contains hidden or 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
# Ranges | |
range_1 = (1..10).to_a # includes the last element | |
p range_1 | |
range_2 = (1...10).to_a # excludes the last element | |
p range_2 | |
# Arrays |
This file contains hidden or 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 acronymize(string) | |
# TODO: write a method that returns | |
# the acronym for the given string | |
# 1. Split the string into words | |
# 2. Take the first letter of each word | |
# & capitalize them | |
# 3. Join the first letters together | |
# 4. Return the result | |
words = string.split(" ") |
This file contains hidden or 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 pick_bank_score | |
# TODO: Use Random to get a new random score | |
# rand(16...21) doesn't include 21 | |
rand (16..21) # includes 21 | |
end | |
def pick_player_card | |
# TODO: Use Random to get a new random card | |
rand(1..11) | |
end |
This file contains hidden or 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
puts "How old are you?" | |
age = gets.chomp.to_i | |
# Conditional Statements | |
# if / else structure | |
if age >= 18 | |
puts "You can vote!" | |
else |
This file contains hidden or 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
require 'date' | |
def days_until_xmas(date = Date.today) | |
# TODO: calculate the number of days | |
# until Christmas | |
current_year = Time.now.year | |
if (Date.new(current_year, 12, 25) - date).to_i < 0 | |
(Date.new(current_year + 1, 12, 25) - date).to_i | |
else | |
(Date.new(current_year, 12, 25) - date).to_i |
This file contains hidden or 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
# "Hello" # string | |
# true # boolean | |
# false # boolean | |
# 3 # integer | |
# 3.14 # float | |
# ["Hello", 3, 3.14, true] # array | |
# (1..10) # range | |
# # String interpolation |
This file contains hidden or 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 Patient | |
attr_reader :name, :cured | |
attr_accessor :id, :room # attr_red + attr_writer | |
# STATE: | |
# - name (String) | |
# - cured (Boolean) | |
# STRATEGY 1 | |
# def initialize(name, cured) |