“Parameter bernama Ruby” Kode Jawaban

Parameter Nama Ruby

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

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

Parameter bernama Ruby

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

Parameter bernama Ruby

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

Jawaban yang mirip dengan “Parameter bernama Ruby”

Pertanyaan yang mirip dengan “Parameter bernama Ruby”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya