Skip to content

Instantly share code, notes, and snippets.

@DevoKun
Last active February 18, 2019 15:57
Show Gist options
  • Save DevoKun/d80334f284f36eba7412 to your computer and use it in GitHub Desktop.
Save DevoKun/d80334f284f36eba7412 to your computer and use it in GitHub Desktop.
Extend IPAddr with a method to return the value of the network range subnet mask
require 'ipaddr'
class IPAddrWithMask < IPAddr
def mask()
## use _to_string private method from IPAddr class
_to_string(@mask_addr)
end ### def
end ### class
net = IPAddrWithMask.new("172.23.0.0/24")
puts net.mask
### 255.255.255.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment