ruby-changes:2137
From: ko1@a...
Date: 5 Oct 2007 03:56:49 +0900
Subject: [ruby-changes:2137] knu - Ruby:r13628 (trunk): * lib/ipaddr.rb (<=>): Implement IPAddr#<=> and make IPAddr
knu 2007-10-05 03:56:32 +0900 (Fri, 05 Oct 2007)
New Revision: 13628
Modified files:
trunk/ChangeLog
trunk/lib/ipaddr.rb
Log:
* lib/ipaddr.rb (<=>): Implement IPAddr#<=> and make IPAddr
comparable.
* lib/ipaddr.rb (succ): Implement IPAddr#succ. You can now create
a range between two IPAddr's, which (Range) object is
enumeratable.
* lib/ipaddr.rb (to_range): A new method to create a Range object
for the (network) address.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/ipaddr.rb?r1=13628&r2=13627
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13628&r2=13627
Index: ChangeLog
===================================================================
--- ChangeLog (revision 13627)
+++ ChangeLog (revision 13628)
@@ -1,3 +1,15 @@
+Fri Oct 5 03:25:51 2007 Akinori MUSHA <knu@i...>
+
+ * lib/ipaddr.rb (<=>): Implement IPAddr#<=> and make IPAddr
+ comparable.
+
+ * lib/ipaddr.rb (succ): Implement IPAddr#succ. You can now create
+ a range between two IPAddr's, which (Range) object is
+ enumeratable.
+
+ * lib/ipaddr.rb (to_range): A new method to create a Range object
+ for the (network) address.
+
Fri Oct 5 03:14:45 2007 Akinori MUSHA <knu@i...>
* lib/ipaddr.rb (coerce_other): Support type coercion and make &,
Index: lib/ipaddr.rb
===================================================================
--- lib/ipaddr.rb (revision 13627)
+++ lib/ipaddr.rb (revision 13628)
@@ -312,6 +312,37 @@
return _reverse + ".ip6.int"
end
+ # Returns the successor to the ipaddr.
+ def succ
+ return self.clone.set(@addr + 1, @family)
+ end
+
+ # Compares the ipaddr with another.
+ def <=>(other)
+ other = coerce_other(other)
+
+ return nil if other.family != @family
+
+ return @addr <=> other.to_i
+ end
+ include Comparable
+
+ # Creates a Range object for the network address.
+ 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
+
# Returns a string containing a human-readable representation of the
# ipaddr. ("#<IPAddr: family:address/mask>")
def inspect
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml