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
# SELECT | |
# INPUT: array | |
# OUTPUT: array which size <= INPUT | |
array = ['Michel Polnareff', 'Michel Jonasz', 'Michel Delpech', 'Maxime Leforestier'] | |
michels = [] | |
array.each do |singer| | |
if singer.split.first == "Michel" | |
michels << singer |
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
# REDUCE | |
# input: array | |
# output: single | |
numbers = [ 21, 36, 54, 18, 11] | |
sum = 0 | |
numbers.each do |number| | |
sum += number | |
end | |
puts sum |
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
# BLOCKS | |
# def a_long_program | |
# puts "doing a very long treatment..." | |
# sleep 4 | |
# end | |
# puts a_long_program | |
# def a_short_program | |
# start = Time.now | |
# puts "doing a very fast treatment..." |
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 bonjour(name) | |
# name.capitalize! | |
# return "Bonjour #{name}" | |
# end | |
# puts bonjour("boris") | |
def yoda_hi(name) | |
return "#{name}, hi!" | |
end | |
puts yoda_hi("luke") |
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
# louchebem translator | |
# let's start with some pseudo-code | |
def louchebemize_word(word) | |
if word.length == 1 | |
return word | |
else | |
vowels = %w(a e i o u y) | |
letters = word.split("") | |
first_vowel_index = letters.find_index do |letter| |
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
require "pry-byebug" | |
def full_name(first_name, last_name) | |
cap_first_name = first_name.strip.capitalize | |
binding.pry | |
cap_last_name = last_name.capitalize | |
return "#{cap_first_name} #{cap_last_name}" | |
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
class Car | |
attr_reader :color, :engine_started, :accessory | |
# Public interface | |
def initialize(color) | |
@color = color | |
@engine_started = false | |
end | |
def start_engine |
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 FacebookUser | |
attr_reader :email, :friends | |
def initialize(options = {}) | |
@name = options[:name] | |
@age = options[:age] | |
@inscription_date = Time.now | |
@email = options[:email] | |
@password = options[:password] | |
@photos = [] |
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 FacebookUser | |
attr_reader :email, :friends | |
def initialize(options = {}) | |
@name = options[:name] | |
@age = options[:age] | |
@inscription_date = Time.now | |
@email = options[:email] | |
@password = options[:password] | |
@photos = [] |
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
require_relative "facebook_user" | |
boris = FacebookUser.new({name: "Boris", email: "boris@lewagon.com", password: "toto"}) | |
boris.add_photo("wwww.mes-photos.com/ma-premiere-photo.jpg") | |
boris.add_photo("ma2emephoto.jpeg") | |
kevin = FacebookUser.new({name: "Kevin", email: "kevin@gmail.com", password: "tata"}) | |
boris.add_friend(kevin) | |
# puts boris.friends | |
p kevin.friends.first.email |