Issue #8047 has been reported by nori_nori (Tadanori Kojima).

----------------------------------------
Feature #8047: IPAddr makes host address with netmask
https://bugs.ruby-lang.org/issues/8047

Author: nori_nori (Tadanori Kojima)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


??躲??IPAddr???????????????广?????????村?????

IPAddr.new("192.168.1.99/24")
 => #<IPAddr: IPv4:192.168.1.0/255.255.255.0> 

????????????????????笺??€?????广?ㄣ????︾?????????????俱????????
?????广?????????村????????广???????????????广????ㄣ????︾???????????
??€?笺????????妗??????俱??
锛?锛??????广?????IP??€?????广?ㄣ?┿????????????笺??????????????????锛?
ex.
IPAddr.new("192.168.1.99/24")
 => #<IPAddr: IPv4:192.168.1.99/255.255.255.0> 


new??浜?寮???般??family??????瀹?????????︺????????32bit?????广??????广????€?????广???с??
寮???般??AF_INET/INET6??俱?????:Host??????般????广????ㄣ????︾?????????????俱??

- IPAddr.new(int, family)
IPAddr.new(3232235875, Socket::AF_INET)
 => #<IPAddr: IPv4:192.168.1.99/255.255.255.255>

- IPAddr.new(ip, :Host)
IPAddr.new("192.168.1.99/24", :Host)
 => #<IPAddr: IPv4:192.168.1.99/255.255.255.0> 

寮???般????????ㄣ?枫?炽???????????ゃ????ゃ????с???????㈠????ㄣ?浮绔???ㄣ??????????ㄣ??
浠ヤ?????????????????????俱??


--- ipaddr.rb.orig      2013-03-08 13:59:07.000000000 +0900
+++ ipaddr.rb   2013-03-08 14:35:06.000000000 +0900
@@ -440,7 +440,7 @@
     else
       raise AddressFamilyError, "unsupported address family"
     end
-    @addr = ((@addr >> masklen) << masklen)
+    @addr = ((@addr >> masklen) << masklen) if @host_mode == false
     return self
   end
 
@@ -477,6 +477,14 @@
         raise AddressFamilyError, "unsupported address family: #{family}"
       end
     end
+
+    if family == :Host 
+      @host_mode = true
+      family = Socket::AF_UNSPEC
+    else
+      @host_mode = false
+    end
+
     prefix, prefixlen = addr.split('/')
     if prefix =~ /^\[(.*)\]$/i
       prefix = $1


-- 
http://bugs.ruby-lang.org/