青木です。
File.chown は引数として nil を受け付けますが、
File#chown に nil を渡すと例外が発生します。
~ % ruby-1.8 -ve 'File.chown nil, nil'
ruby 1.8.3 (2005-09-19) [x86_64-linux]
~ % ruby-1.8 -ve 'File.open(".") {|f| f.chown nil, nil }'
ruby 1.8.3 (2005-09-19) [x86_64-linux]
-e:1:in `chown': no implicit conversion from nil to integer (TypeError)
from -e:1
from -e:1
~ % ruby -ve 'File.chown nil, nil'
ruby 1.9.0 (2005-09-18) [x86_64-linux]
~ % ruby -ve 'File.open(".") {|f| f.chown nil, nil }'
ruby 1.9.0 (2005-09-18) [x86_64-linux]
-e:1:in `chown': no implicit conversion from nil to integer (TypeError)
from -e:1
from -e:1
この挙動は一貫性がなく、不適切だと思います。また、英語・日本語リファレンスの
どちらにも nil を受け付けると書いてあります。
chown(owner, group)
:
:
owner と group は、chown(2) と同様に数値で指定します。 nil または -1 を指定
することでオーナーやグループを現在のままにすることができます。
* call-seq:
* file.chown(owner_int, group_int ) => 0
*
* Changes the owner and group of <i>file</i> to the given numeric
* owner and group id's. Only a process with superuser privileges may
* change the owner of a file. The current owner of a file may change
* the file's group to any group to which the owner belongs. A
* <code>nil</code> or -1 owner or group id is ignored. Follows
* symbolic links. See also <code>File#lchown</code>.
nil を許すようにしたパッチを添付します。
--
青木峰郎
Index: file.c
===================================================================
RCS file: /var/cvs/src/ruby/file.c,v
retrieving revision 1.207
diff -u -r1.207 file.c
--- file.c 18 Sep 2005 18:29:14 -0000 1.207
+++ file.c 18 Sep 2005 19:02:32 -0000
@@ -1745,8 +1745,8 @@
int o, g;
rb_secure(2);
- o = NUM2INT(owner);
- g = NUM2INT(group);
+ o = NIL_P(owner) ? -1 : NUM2INT(owner);
+ g = NIL_P(group) ? -1 : NUM2INT(group);
GetOpenFile(obj, fptr);
#if defined(DJGPP) || defined(__CYGWIN32__) || defined(_WIN32) || defined(__EMX__)
if (!fptr->path) return Qnil;