“Ruby Named Paramètres” Réponses codées

paramètres de nom de rubis

def foo(bar: 'default')
  puts bar
end

foo # => 'default'
foo(bar: 'baz') # => 'baz'
Dev Pro

Ruby Named Paramètres

def show_name_and_address(name: "Someone", address: "Somewhere")
  puts "#{name}, #{address}"
end

show_name_and_address
#=> 'Someone, Somewhere'

show_name_and_address(name: 'Andy')
#=> 'Andy, Somewhere'

show_name_and_address(address: 'USA')
#=> 'Someone, USA'
Enchanting Eel

Ruby Named Paramètres

def show_name_and_address(name="Someone", address="Somewhere")
  puts "#{name}, #{address}"
end

show_name_and_address
#=> 'Someone, Somewhere'

show_name_and_address('Andy')
#=> 'Andy, Somewhere'
Enchanting Eel

Réponses similaires à “Ruby Named Paramètres”

Questions similaires à “Ruby Named Paramètres”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code