proc = Proc.new do |name|
puts "Thank you #{name}!"
end
def thank
yield
end
proc.call # output nothing, just fine
proc.call('God') # => Thank you God!
thank &proC# output nothing, too. Fine;
thank &proc('God') # Error!
thank &proc.call('God') # Error!
thank proc.call('God') # Error!
# So, what should I do if I have to pass the 'God' to the proc and use the 'thank' method at the same time ?
Merci :)Comment passer des paramètres à un proc en l'appelant par une méthode? (Rubis)
Vous devez ajouter 2 espaces avant chaque ligne de code afin d'en faire un exemple de code dans votre réponse. Il semblera plus joli et ajoutera la syntaxe soulignant à toutes vos lignes de code. – David
Pas besoin de ', & block' –
@ Marc-André Lafortune: Vous parlez de la définition de« merci », pas de l'appel, n'est-ce pas? –