Usage of keyword arguments

Issue #1 new
Dirk Heinrichs created an issue

Just tried Net::Ping and found out the hard way that using something like

icmp = Net::Ping::ICMP.new(host='somehost', timeout=1)

does not work, icmp.ping will always return false, since the 2nd argument (port) wasn’t provided (although it has a default value). It also doesn’t work if the order differs from the one given in the method signature.

If the signature was changed to

def initialize(host:, port: nil, timeout: 5)

aka “Keyword arguments”, neither port would be required, nor would ordering matter anymore. One could simply write

icmp = Net::Ping::ICMP.new(timeout: 1, host: 'somehost')

or just

icmp = Net::Ping::ICMP.new('somehost')

Comments (2)

  1. Log in to comment