Method: Ip#cidr
- Defined in:
- lib/ipcalc/Ip.rb
#cidr(in_class) ⇒ Object
Return the CIDR of a given subnet’s class that contains this IP address.
- in_class
-
Class of the subnet (example: 26).
The method returns the CIDR of the given class that contains this IP address.
237 238 239 240 241 242 |
# File 'lib/ipcalc/Ip.rb', line 237 def cidr(in_class) max_class = MAX_CLASS() raise RuntimeError, "Invalid subnet class /#{in_class}" if (in_class > max_class || in_class < 1) mask = (2**in_class - 1) << (max_class - in_class) Iptools.i_to_dots(@ip_int & mask, @version) + "/#{in_class}" end |