###Cheat Sheet RUBY and rails
-
-
Save cyrilferte/300b9149bc80250f3ec74d1b2fea3aa5 to your computer and use it in GitHub Desktop.
pas de saut de ligne "#{x}\n"
identites_secretes = {
"The Batman" => "Bruce Wayne",
"Superman" => "Clark Kent",
"Wonder Woman" => "Diana Prince",
"Freakazoid" => "Dexter Douglas"
}
identites_secretes.each { |hero, nom| puts "#{hero}: #{nom}"}
hash
prix = {
"pomme" => 0.52,
"banane" => 0.23,
"kiwi" => 1.42
}
sons = Hash.new
sons["chien"] = "ouaf"
sons["chat"] = "miaou"
puts "Veuillez entrer un texte : "
texte = gets.chomp
mots = texte.split(" ")
frequences = Hash.new(0)
mots.each { |mot| frequences[mot] += 1 }
frequences = frequences.sort_by {|a, b| b }
frequences.reverse!
frequences.each { |mot, frequence| puts mot + " " + frequence.to_s }
def majuscule(string)
puts "#{string[0].upcase}#{string[1..-1]}"
end
majuscule("ryan comment va tu ?") # affiche "Ryan comment va tu ?"
majuscule("jane") # affiche "Jane"
groupe_1 = [4.1, 5.5, 3.2, 3.3, 6.1, 3.9, 4.7]
groupe_2 = [7.0, 3.8, 6.2, 6.1, 4.4, 4.9, 3.0]
groupe_3 = [5.5, 5.1, 3.9, 4.3, 4.9, 3.2, 3.2]
proc
assez_grand = Proc.new { |hauteur| hauteur>= 4 }
variable in texte
"Solde: $#{@solde}."
next (in loop)
next if i % 2 == 0 # pair
next if i % 2 == 0 # impair