[#31928] securerandom.rb for 1.8 — Tanaka Akira <akr@...>

securerandom.rb を 1.8 に追加し、cgi/session.rb に使わせたい

18 messages 2007/10/03
[#31990] Re: securerandom.rb for 1.8 — "Akinori MUSHA" <knu@...> 2007/10/09

At Wed, 3 Oct 2007 12:49:20 +0900,

[#31992] Re: securerandom.rb for 1.8 — Tanaka Akira <akr@...> 2007/10/09

In article <86k5pwinco.knu@iDaemons.org>,

[#31993] Re: securerandom.rb for 1.8 — "NAKAMURA, Hiroshi" <nakahiro@...> 2007/10/09

-----BEGIN PGP SIGNED MESSAGE-----

[#31936] Rake添付 — Yukihiro Matsumoto <matz@...>

まつもと ゆきひろです

21 messages 2007/10/04
[#31937] Re: Rake添付 — "NAKAMURA, Hiroshi" <nakahiro@...> 2007/10/04

-----BEGIN PGP SIGNED MESSAGE-----

[#31938] Re: Rake添付 — Yukihiro Matsumoto <matz@...> 2007/10/04

まつもと ゆきひろです

[#31941] Re: [ruby-list:44071] Re: Ruby 1.8.6-p111 / 1.8.5-p114 released (Security Fix) — Shugo Maeda <shugo@...>

前田です。

20 messages 2007/10/04
[#31943] Re: [ruby-list:44071] Re: Ruby 1.8.6-p111 / 1.8.5-p114 released (Security Fix) — "NAKAMURA, Hiroshi" <nakahiro@...> 2007/10/05

-----BEGIN PGP SIGNED MESSAGE-----

[#31945] Re: [ruby-list:44071] Re: Ruby 1.8.6-p111 / 1.8.5-p114 released (Security Fix) — Shugo Maeda <shugo@...> 2007/10/05

前田です。

[#31948] Re: [ruby-list:44071] Re: Ruby 1.8.6-p111 / 1.8.5-p114 released (Security Fix) — "NAKAMURA, Hiroshi" <nakahiro@...> 2007/10/05

-----BEGIN PGP SIGNED MESSAGE-----

[#31952] Re: [ruby-list:44071] Re: Ruby 1.8.6-p111 / 1.8.5-p114 released (Security Fix) — Shugo Maeda <shugo@...> 2007/10/05

前田です。

[#31956] Re: [ruby-list:44071] Re: Ruby 1.8.6-p111 / 1.8.5-p114 released (Security Fix) — GOTOU Yuuzou <gotoyuzo@...> 2007/10/06

In message <47063403.3070402@ruby-lang.org>,

[#31960] Re: [ruby-list:44071] Re: Ruby 1.8.6-p111 / 1.8.5-p114 released (Security Fix) — GOTOU Yuuzou <gotoyuzo@...> 2007/10/07

In message <20071006.101915.596518898.gotoyuzo@sawara.priv.tokyo.netlab.jp>,

[#31980] multibyte string/regex literal with escape sequence — "U.Nakamura" <usa@...>

こんにちは、なかむら(う)です。

24 messages 2007/10/09
[#31981] Re: multibyte string/regex literal with escape sequence — Yukihiro Matsumoto <matz@...> 2007/10/09

まつもと ゆきひろです

[#31983] Re: multibyte string/regex literal with escape sequence — "U.Nakamura" <usa@...> 2007/10/09

こんにちは、なかむら(う)です。

[#31984] Re: multibyte string/regex literal with escape sequence — Yukihiro Matsumoto <matz@...> 2007/10/09

まつもと ゆきひろです

[#31986] Re: multibyte string/regex literal with escape sequence — "U.Nakamura" <usa@...> 2007/10/09

こんにちは、なかむら(う)です。

[#31987] Re: multibyte string/regex literal with escape sequence — Yukihiro Matsumoto <matz@...> 2007/10/09

まつもと ゆきひろです

[#32003] Re: multibyte string/regex literal with escape sequence — "U.Nakamura" <usa@...> 2007/10/10

こんにちは、なかむら(う)です。

[#32133] undefined method `now' for DateTime:Class (NoMethodError) — "NAKAMURA, Hiroshi" <nakahiro@...>

-----BEGIN PGP SIGNED MESSAGE-----

12 messages 2007/10/23
[#32135] Re: undefined method `now' for DateTime:Class (NoMethodError) — tadf@... 2007/10/23

どういう状況かよくわかってないのですが、いっそ必ず date 丸ごと読むようにするか、

[#32136] Re: undefined method `now' for DateTime:Class (NoMethodError) — "NAKAMURA, Hiroshi" <nakahiro@...> 2007/10/23

-----BEGIN PGP SIGNED MESSAGE-----

[ruby-dev:31925] Re: ipaddr

From: "Akinori MUSHA" <knu@...>
Date: 2007-10-02 11:17:14 UTC
List: ruby-dev #31925
At Sun, 30 Sep 2007 00:27:59 +0900,
Kazuhiro NISHIYAMA wrote:
> 西山和広です。
>
> ipaddrで
>  IPAddr.new("127.0.0.0/8").include?("127.0.0.1")
> がfalseになって悩んだことがあるので、文字列も自動で変換して
> うけつけてくれると嬉しいのではないかと思います。
>
> # 今は
> #  IPAddr.new("127.0.0.0/8").include?(IPAddr.new("127.0.0.1"))
> # じゃないとだめ。

 こうするといいかな。

Index: ipaddr.rb
===================================================================
--- ipaddr.rb	(revision 13588)
+++ ipaddr.rb	(working copy)
@@ -105,14 +105,26 @@
     return s
   end

+  def coerce(other)
+    case other
+    when IPAddr
+      other
+    when String
+      self.class.new(other)
+    else
+      self.class.new(other, @family)
+    end
+  end
+  private coerce
+
   # Returns a new ipaddr built by bitwise AND.
   def &(other)
-    return self.clone.set(@addr & other.to_i)
+    return self.clone.set(@addr & coerce(other).to_i)
   end

   # Returns a new ipaddr built by bitwise OR.
   def |(other)
-    return self.clone.set(@addr | other.to_i)
+    return self.clone.set(@addr | coerce(other).to_i)
   end

   # Returns a new ipaddr built by bitwise right-shift.
@@ -132,10 +144,7 @@

   # Returns true if two ipaddr are equal.
   def ==(other)
-    if other.kind_of?(IPAddr) && @family != other.family
-      return false
-    end
-    return (@addr == other.to_i)
+    return @family == other.family && @addr == coerce(other).to_i
   end

   # Returns a new ipaddr built by masking IP address with the given
@@ -153,6 +162,7 @@
   #   p net1.include?(IPAddr.new("192.168.2.255"))	#=> true
   #   p net1.include?(IPAddr.new("192.168.3.0"))	#=> false
   def include?(other)
+    other = coerce(other)
     if ipv4_mapped?
       if (@mask_addr >> 32) != 0xffffffffffffffffffffffff
 	return false
@@ -165,17 +175,12 @@
       addr = @addr
       family = @family
     end
-    if other.kind_of?(IPAddr)
-      if other.ipv4_mapped?
-	other_addr = (other.to_i & IN4MASK)
-	other_family = Socket::AF_INET
-      else
-	other_addr = other.to_i
-	other_family = other.family
-      end
-    else # Not IPAddr - assume integer in same family as us
-      other_addr   = other.to_i
-      other_family = family
+    if other.ipv4_mapped?
+      other_addr = (other.to_i & IN4MASK)
+      other_family = Socket::AF_INET
+    else
+      other_addr = other.to_i
+      other_family = other.family
     end

     if family != other_family


 ついでに <=> と succ を定義して Comparable にすると、 Range を
作ったりできますね。

> # ライブラリのメンテナの話で思いだした。

 梅本さんにCCしておきます。

--
                     /
                    /__  __            Akinori.org / MUSHA.org
                   / )  )  ) )  /     FreeBSD.org / Ruby-lang.org
Akinori MUSHA aka / (_ /  ( (__(  @ iDaemons.org / and.or.jp

"Different eyes see different things,
    Different hearts beat on different strings --
       But there are times for you and me when all such things agree"

In This Thread

Prev Next