Skip to content

Instantly share code, notes, and snippets.

@cyrilferte
Created October 13, 2016 19:23
Show Gist options
  • Save cyrilferte/300b9149bc80250f3ec74d1b2fea3aa5 to your computer and use it in GitHub Desktop.
Save cyrilferte/300b9149bc80250f3ec74d1b2fea3aa5 to your computer and use it in GitHub Desktop.

###Cheat Sheet RUBY and rails

@cyrilferte
Copy link
Author

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 }

@cyrilferte
Copy link
Author

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"

@cyrilferte
Copy link
Author

cyrilferte commented Oct 15, 2016

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 }

@cyrilferte
Copy link
Author

variable in texte
"Solde: $#{@solde}."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment