Une collection organisée de snippets de code pour accélérer votre développement. Parcourez, recherchez et copiez en un clic.
mon_proc = Proc.new { |x| puts x * 2 }
[1, 2, 3].each(&mon_proc)
ma_lambda = ->(x) { x * 2 }
def saluer(nom)
"Bonjour, #{nom}!"
end
def saluer(nom = "Invité")
"Bonjour, #{nom}!"
end
def creer_utilisateur(nom:, age:)
puts "#{nom} a #{age} ans."
end
creer_utilisateur(nom: "Alice", age: 30)
def mon_iterateur
yield
yield
end
mon_iterateur { puts "Dans le bloc !" }
def avec_index
yield "a", 0
yield "b", 1
end
avec_index { |lettre, index| puts "#{index}: #{lettre}" }