[ruby-list:37670] Re: node existence test in XTemplate

From: Tanaka Akira <akr@...17n.org>
Date: 2003-05-09 16:47:51 UTC
List: ruby-list #37670
In article <877k90sjrk.fsf@serein.a02.aist.go.jp>,
  Tanaka Akira <akr@m17n.org> writes:

> これってなんでなんでしょうか?

立石さんに修正方法の詳細を(日本語で)教えてもらったので、次のように変え
てみたところ意図通りに動くようになりました。

Index: lib/xtemplate/xpath.rb
===================================================================
RCS file: /cvsroot/xtemplate/xtemplate/lib/xtemplate/xpath.rb,v
retrieving revision 1.59
diff -u -r1.59 xpath.rb
--- lib/xtemplate/xpath.rb	17 Mar 2003 01:19:31 -0000	1.59
+++ lib/xtemplate/xpath.rb	9 May 2003 16:44:35 -0000
@@ -1057,10 +1057,10 @@
     end
 
     def eval_condition(expr, val, plugin)
-      if( expr.include?("or") )
-	expr.split("or").any?{|x| eval_condition(x.strip,val,plugin) }
-      elsif( expr.include?("and") )
-	expr.split("and").all?{|x| eval_condition(x.strip,val,plugin) }
+      if( expr =~ /\s+or\s+/ )
+	expr.split(/\s+or\s+/).any?{|x| eval_condition(x.strip,val,plugin) }
+      elsif( expr =~ /\s+and\s+/ )
+	expr.split(/\s+and\s+/).all?{|x| eval_condition(x.strip,val,plugin) }
       elsif( expr =~ /^not\s+(.+)$/ )
 	! eval_condition($1.strip,val,plugin)
       else
Index: lib/xtemplate/util.rb
===================================================================
RCS file: /cvsroot/xtemplate/xtemplate/lib/xtemplate/util.rb,v
retrieving revision 1.5
diff -u -r1.5 util.rb
--- lib/xtemplate/util.rb	16 Feb 2003 18:55:18 -0000	1.5
+++ lib/xtemplate/util.rb	9 May 2003 16:44:34 -0000
@@ -1,6 +1,6 @@
 # -*- ruby -*-
 
-if( !Enumerable.instance_methods.include?("all?") )
+if( !Enumerable.instance_methods(false).include?("all?") )
   module Enumerable
     def all?
       each{|v|

(lib/xtemplate/util.rb は警告避けのおまけです。)
-- 
[田中 哲][たなか あきら][Tanaka Akira]

In This Thread