[#10492] Ruby 1.8.6 preview3 has been released — "Akinori MUSHA" <knu@...>

Hi,

26 messages 2007/03/04
[#10500] Re: Ruby 1.8.6 preview3 has been released — Hugh Sasse <hgs@...> 2007/03/05

On Mon, 5 Mar 2007, Akinori MUSHA wrote:

[#10507] Dynamic Array#join with block — <noreply@...>

Patches item #9055, was opened at 2007-03-05 19:57

12 messages 2007/03/05
[#10520] Re: [ ruby-Patches-9055 ] Dynamic Array#join with block — Nobuyoshi Nakada <nobu@...> 2007/03/06

Hi,

[#10594] grave bug in 1.8.6's thread implementation — Sylvain Joyeux <sylvain.joyeux@...4x.org>

In ext/thread/thread.c, remove_one leaves the list in an inconsistent state.

15 messages 2007/03/14
[#10596] Re: [PATCH] grave bug in 1.8.6's thread implementation — MenTaLguY <mental@...> 2007/03/14

On Thu, 15 Mar 2007 00:15:57 +0900, Sylvain Joyeux <sylvain.joyeux@m4x.org> wrote:

[#10597] Re: [PATCH] grave bug in 1.8.6's thread implementation — Sylvain Joyeux <sylvain.joyeux@...4x.org> 2007/03/14

> > The fix is in thread-mutex-remove_one.diff.

[#10598] Re: [PATCH] grave bug in 1.8.6's thread implementation — MenTaLguY <mental@...> 2007/03/14

On Thu, 15 Mar 2007 01:19:04 +0900, Sylvain Joyeux <sylvain.joyeux@m4x.org> wrote:

[#10599] Re: [PATCH] grave bug in 1.8.6's thread implementation — Sylvain Joyeux <sylvain.joyeux@...4x.org> 2007/03/14

On Wednesday 14 March 2007 17:29, MenTaLguY wrote:

[#10600] Re: [PATCH] grave bug in 1.8.6's thread implementation — MenTaLguY <mental@...> 2007/03/14

On Thu, 15 Mar 2007 01:48:42 +0900, Sylvain Joyeux <sylvain.joyeux@m4x.org> wrote:

[#10615] Multiton in standard library — TRANS <transfire@...>

Hi--

16 messages 2007/03/15
[#10619] Re: Multiton in standard library — Tom Pollard <tomp@...> 2007/03/16

[#10620] Re: Multiton in standard library — TRANS <transfire@...> 2007/03/16

On 3/15/07, Tom Pollard <tomp@earthlink.net> wrote:

[#10646] Marshal.dump shouldn't complain about singletons if the _dump method is defined — <noreply@...>

Bugs item #9376, was opened at 2007-03-19 15:58

12 messages 2007/03/19
[#10647] Re: [ ruby-Bugs-9376 ] Marshal.dump shouldn't complain about singletons if the _dump method is defined — Urabe Shyouhei <shyouhei@...> 2007/03/19

noreply@rubyforge.org wrote:

[#10648] Re: [ ruby-Bugs-9376 ] Marshal.dump shouldn't complain about singletons if the _dump method is defined — Sylvain Joyeux <sylvain.joyeux@...4x.org> 2007/03/19

On Monday 19 March 2007 18:01, Urabe Shyouhei wrote:

[#10651] Re: [ ruby-Bugs-9376 ] Marshal.dump shouldn't complain about singletons if the _dump method is defined — Yukihiro Matsumoto <matz@...> 2007/03/19

Hi,

[#10665] Re: [ ruby-Bugs-9376 ] Marshal.dump shouldn't complain about singletons if the _dump method is defined — "Chris Carter" <cdcarter@...> 2007/03/20

On 3/19/07, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:

[#10712] Ruby Method Signatures (was Re: Multiton in standard library) — "Rick DeNatale" <rick.denatale@...>

On 3/19/07, TRANS <transfire@gmail.com> wrote:

10 messages 2007/03/21
[#10715] Re: Ruby Method Signatures (was Re: Multiton in standard library) — Jos Backus <jos@...> 2007/03/22

On 3/19/07, TRANS <transfire@gmail.com> wrote:

[#10798] Virtual classes and 'real' classes -- why? — "John Lam (CLR)" <jflam@...>

I was wondering if someone could help me understand why there's a parallel =

12 messages 2007/03/28
[#10799] Re: Virtual classes and 'real' classes -- why? — MenTaLguY <mental@...> 2007/03/28

On Thu, 29 Mar 2007 04:44:16 +0900, "John Lam (CLR)" <jflam@microsoft.com> wrote:

Extensions to ipaddr.rb

From: b.candler@...
Date: 2007-03-21 10:11:10 UTC
List: ruby-core #10698
I'd like to contribute the following extensions to ipaddr.rb 

They allow the following constructs: 

 puts IPAddr.new("192.168.0.0") + 1          # => 192.168.0.1
 puts IPAddr.new("192.168.0.0") - 1          # => 192.167.255.255
 puts IPAddr.new("192.168.0.0/24").netmask   # => 255.255.255.0
 puts IPAddr.new("192.168.0.0/24").prefixlen # => 24
 puts IPAddr.new("192.168.0.0/24").size      # => 256 

Regards, 

Brian Candler. 


Attachments (1)

ipaddr.rb.diff (3.96 KB, text/x-diff)
--- /usr/lib/ruby/1.8/ipaddr.rb	2006-08-04 23:00:21.000000000 +0100
+++ ipaddr.rb	2007-03-21 10:11:55.000000000 +0000
@@ -125,6 +125,16 @@
     return self.clone.set(addr_mask(@addr << num))
   end
 
+  # Returns a new ipaddr built by addition.
+  def +(other)
+    return self.clone.set(@addr + other.to_i)
+  end
+
+  # Returns a new ipaddr built by subtraction.
+  def -(other)
+    return self.clone.set(@addr - other.to_i)
+  end
+
   # Returns a new ipaddr built by bitwise negation.
   def ~
     return self.clone.set(addr_mask(~@addr))
@@ -331,6 +341,37 @@
 		   af, _to_string(@addr), _to_string(@mask_addr))
   end
 
+  # Return just the netmask.
+  def netmask
+    _to_string(@mask_addr)
+  end
+
+  # Return just the prefix length.
+  def prefixlen
+    m = case @family
+    when Socket::AF_INET
+      IN4MASK
+    when Socket::AF_INET6
+      IN6MASK
+    else
+      raise "unsupported address family"
+    end
+    return $1.length if /\A(1*)(0*)\z/ =~ (@mask_addr & m).to_s(2)
+    raise "bad addr_mask format"
+  end
+
+  # Return the number of IP addresses in the block.
+  def size
+    case @family
+    when Socket::AF_INET
+      ((~@mask_addr) & IN4MASK) + 1
+    when Socket::AF_INET6
+      ((~@mask_addr) & IN6MASK) + 1
+    else
+      raise "unsupported address family"
+    end
+  end
+
   protected
 
   def set(addr, *family)
@@ -547,6 +588,9 @@
     a = IPAddr.new("0123:4567:89ab:cdef:0ABC:DEF0:1234:5678")
     assert_equal("123:4567:89ab:cdef:abc:def0:1234:5678", a.to_s)
     assert_equal("0123:4567:89ab:cdef:0abc:def0:1234:5678", a.to_string)
+    assert_equal("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", a.netmask)
+    assert_equal(128, a.prefixlen)
+    assert_equal(1, a.size)
     assert_equal(Socket::AF_INET6, a.family)
 
     a = IPAddr.new("3ffe:505:2::/48")
@@ -556,6 +600,9 @@
     assert_equal(false, a.ipv4?)
     assert_equal(true, a.ipv6?)
     assert_equal("#<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0000/ffff:ffff:ffff:0000:0000:0000:0000:0000>", a.inspect)
+    assert_equal("ffff:ffff:ffff:0000:0000:0000:0000:0000", a.netmask)
+    assert_equal(48, a.prefixlen)
+    assert_equal(1 << 80, a.size)
 
     a = IPAddr.new("3ffe:505:2::/ffff:ffff:ffff::")
     assert_equal("3ffe:505:2::", a.to_s)
@@ -566,6 +613,16 @@
     assert_equal("0.0.0.0", a.to_s)
     assert_equal("0.0.0.0", a.to_string)
     assert_equal(Socket::AF_INET, a.family)
+    assert_equal("#<IPAddr: IPv4:0.0.0.0/255.255.255.255>", a.inspect)
+    assert_equal("255.255.255.255", a.netmask)
+    assert_equal(32, a.prefixlen)
+    assert_equal(1, a.size)
+
+    a = IPAddr.new("0.0.0.0/0")
+    assert_equal("#<IPAddr: IPv4:0.0.0.0/0.0.0.0>", a.inspect)
+    assert_equal("0.0.0.0", a.netmask)
+    assert_equal(0, a.prefixlen)
+    assert_equal(1 << 32, a.size)
 
     a = IPAddr.new("192.168.1.2")
     assert_equal("192.168.1.2", a.to_s)
@@ -579,11 +636,17 @@
     assert_equal("192.168.1.0", a.to_string)
     assert_equal(Socket::AF_INET, a.family)
     assert_equal("#<IPAddr: IPv4:192.168.1.0/255.255.255.0>", a.inspect)
+    assert_equal("255.255.255.0", a.netmask)
+    assert_equal(24, a.prefixlen)
+    assert_equal(256, a.size)
 
     a = IPAddr.new("192.168.1.2/255.255.255.0")
     assert_equal("192.168.1.0", a.to_s)
     assert_equal("192.168.1.0", a.to_string)
     assert_equal(Socket::AF_INET, a.family)
+    assert_equal("255.255.255.0", a.netmask)
+    assert_equal(24, a.prefixlen)
+    assert_equal(256, a.size)
 
     assert_equal("0:0:0:1::", IPAddr.new("0:0:0:1::").to_s)
     assert_equal("2001:200:300::", IPAddr.new("2001:200:300::/48").to_s)
@@ -728,6 +791,16 @@
     assert_equal("3ffe:505:2::", @a.to_s)
   end
 
+  def test_add
+    a = IPAddr.new("3ffe:505:2:1:ffff:ffff:ffff:fffd")
+    assert_equal("3ffe:505:2:1:ffff:ffff:ffff:fffe", (a + 1).to_s)
+    assert_equal("3ffe:505:2:2::", (a + 3).to_s)
+  end
+
+  def test_sub
+    assert_equal("3ffe:505:1:ffff:ffff:ffff:ffff:ffff", (@a - 1).to_s)
+  end
+
   def test_carrot
     a = ~@in6_addr_any
     assert_equal(IN6MASK128, a.to_s)

In This Thread

Prev Next