Class: IPAddr
- Inherits:
-
Object
- Object
- IPAddr
- Includes:
- Comparable
- Defined in:
- lib/rack/ketai/carrier/abstract.rb
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compares the ipaddr with another.
- #coerce_other(other) ⇒ Object
-
#succ ⇒ Object
Returns the successor to the ipaddr.
- #to_range ⇒ Object
Instance Method Details
#<=>(other) ⇒ Object
Compares the ipaddr with another.
31 32 33 34 35 36 37 |
# File 'lib/rack/ketai/carrier/abstract.rb', line 31 def <=>(other) other = coerce_other(other) return nil if other.family != @family return @addr <=> other.to_i end |
#coerce_other(other) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rack/ketai/carrier/abstract.rb', line 14 def coerce_other(other) case other when IPAddr other when String self.class.new(other) else self.class.new(other, @family) end end |
#succ ⇒ Object
Returns the successor to the ipaddr.
26 27 28 |
# File 'lib/rack/ketai/carrier/abstract.rb', line 26 def succ return self.clone.set(@addr + 1, @family) end |
#to_range ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rack/ketai/carrier/abstract.rb', line 40 def to_range begin_addr = (@addr & @mask_addr) case @family when Socket::AF_INET end_addr = (@addr | (IN4MASK ^ @mask_addr)) when Socket::AF_INET6 end_addr = (@addr | (IN6MASK ^ @mask_addr)) else raise "unsupported address family" end return clone.set(begin_addr, @family)..clone.set(end_addr, @family) end |