Class: IPAddr
- Inherits:
-
Object
- Object
- IPAddr
- Defined in:
- lib/pg_funcall/ipaddr_monkeys.rb
Overview
TODO: we probably shouldn’t do go around monkey-patching like this.
Instance Method Summary collapse
Instance Method Details
#as_json(options = {}) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/pg_funcall/ipaddr_monkeys.rb', line 19 def as_json( = {}) if (ipv6? && prefixlen == 64) || (ipv4? && prefixlen == 32) to_s else to_cidr_string end end |
#prefixlen ⇒ Object
8 9 10 11 12 13 |
# File 'lib/pg_funcall/ipaddr_monkeys.rb', line 8 def prefixlen mask = @mask_addr len = 0 len += mask & 1 and mask >>= 1 until mask == 0 len end |
#to_cidr_string ⇒ Object
15 16 17 |
# File 'lib/pg_funcall/ipaddr_monkeys.rb', line 15 def to_cidr_string "#{to_s}/#{prefixlen}" end |