[#45609] ruby 1.8.6のNKFにおける漢字変換の不具合について — 京和 崇行 <kyowa_t@...>

初めましてこんにちは。カカクコムの京和と申します。

14 messages 2008/11/04

[ruby-list:45634] Shell#[] が動かない。

From: Kouya <kouyataifu4@...>
Date: 2008-11-12 12:52:16 UTC
List: ruby-list #45634
こんばんは、kouyaです。

Shell のリファレンスマニュアルを書いています。

下記スクリプトが ruby 1.8 で動作しなかったので、(1.9では動いた)
ソースの方を修正すると動きましたので、報告させていただきます。

  require 'shell'
  Shell.verbose = false
  sh = Shell.new
  begin
    sh.mkdir("foo")
  rescue
  end
  p  sh[?e, "foo"]
  p  sh[:e, "foo"]
  p  sh["e", "foo"]
  p  sh[:exists?, "foo"]
  p  sh["exists?", "foo"]

結果
[kouya:shell]$ ruby  -v s.rb
ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-darwin9.2.0]
(eval):5: warning: discarding old Fail
(eval):7: warning: redefine included
/opt/local/lib/ruby/1.8/shell.rb:43: warning: method redefined;
discarding old debug=
/opt/local/lib/ruby/1.8/shell.rb:107: warning: method redefined;
discarding old debug=
/opt/local/lib/ruby/1.8/shell.rb:55: warning: instance variable
@default_system_path not initialized
/opt/local/lib/ruby/1.8/shell.rb:67: warning: instance variable
@default_record_separator not initialized
/opt/local/lib/ruby/1.8/shell/command-processor.rb:165:in `[]':
undefined method `top_level_test' for
#<Shell::CommandProcessor:0x94a48> (NoMethodError)
	from /opt/local/lib/ruby/1.8/shell/command-processor.rb:519:in `__send__'
	from /opt/local/lib/ruby/1.8/shell/command-processor.rb:519:in `[]'
	from s.rb:220


修正箇所

Index: lib/shell/command-processor.rb
===================================================================
--- lib/shell/command-processor.rb	(revision 20228)
+++ lib/shell/command-processor.rb	(working copy)
@@ -155,6 +155,7 @@
     #	  sh[:exists?, "foo"]
     #	  sh["exists?", "foo"]
     #	
+    alias top_level_test test
     def test(command, file1, file2=nil)
       file1 = expand_path(file1)
       file2 = expand_path(file2) if file2
@@ -162,7 +163,11 @@

       case command
       when Integer
-	top_level_test(command, file1, file2)
+        if file2
+	  top_level_test(command, file1, file2)
+        else
+	  top_level_test(command, file1)
+        end
       when String
 	if command.size == 1
 	  if file2

-- 
kouya

In This Thread

Prev Next