From dcd3e2d4984e66565d568275833ee0addf3e961c Mon Sep 17 00:00:00 2001 From: Herwin Weststrate Date: Mon, 16 Oct 2017 19:56:18 +0200 Subject: [PATCH] Cleaner way to write class methods * Use `def self.` instead of repeating the classname * Don't prefix class methods with the class from inside class methods --- lib/ipaddr.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ipaddr.rb b/lib/ipaddr.rb index ad99782..be7b8c0 100644 --- a/lib/ipaddr.rb +++ b/lib/ipaddr.rb @@ -103,13 +103,13 @@ class InvalidPrefixError < InvalidAddressError; end # Creates a new ipaddr containing the given network byte ordered # string form of an IP address. - def IPAddr::new_ntoh(addr) - return IPAddr.new(IPAddr::ntop(addr)) + def self.new_ntoh(addr) + return new(ntop(addr)) end # Convert a network byte ordered string form of an IP address into # human readable form. - def IPAddr::ntop(addr) + def self.ntop(addr) case addr.size when 4 s = addr.unpack('C4').join('.')