From: Bob Alexander Date: 2002-03-15T03:28:58+09:00 Subject: Re: Some potential RCRs [Comments Summarized] Following are summarized responses to the passle of RCR candidates I posted recently. As soon as I have time (within a couple of days, I hope), I will submit these as RCRs at the Ruby Garden site (http://www.rubygarden.org/index.php?topic=RCR), so register your votes and concerns there. I removed some the the descriptive text in the original from this email -- the original is in the mail archive at (http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/35653). Thanks to all who responded. ------------------ "p" method should return its last argument, unconverted. Comments were all positive. The only concern was that in an interactive (irb) context, the returned value will be printed (again). The objector retracted the objection when I pointed out that "p" is really for non-interactive use, since simply typing an expression in irb (without the "p") prints the value. ------------------ A format specification in "printf"-type formats that inserts the result of applying "inspect" to the argument (similar to how %s inserts argument.to_s) The only comment was that the %r specification letter I used in my example might not be the best choice. I agree. I'll try to propose the perfect letter in the RCR, after extensive research. Ideas? ------------------ A "println" method. (println "hello", " ", "there" ==> print "hello", " ", "there", "\n") Some liked the idea, some didn't see the need. I like it since I like the method name to convey my intent, so I'll submit the RCR. ------------------ String#count should also accept Regexp as argument. Clarification was requested. My intent was that it would still work as it currently does, but if a single Regexp is provided instead of a strings, it would count non-overlapping matches of the Regexp: class String alias old_count count def count(*args) if args.length == 1 && args.first.kind_of?(Regexp) count = 0 scan(args.first) {count += 1} count else old_count(*args) end end end Maybe a different method name should be chosen (??) (although I don't really think it's necessary -- this use seems very intuitive to me). String#matches ? ------------------ Dir methods that produce directory entries should never produce "." and "..". There were some strenuous objections to this, and some liked it. Since few can deny the inconvenience of having to filter out the "self" and "parent" entries ('.' and '..') in practically all applications except a simulated "ls -a" command, I'll modify the original suggestion to providing new methods that do not produce the special names that do not actually represent directory "contents" per se: Dir::contents(path) Dir::each_name(path) (Suggestions for better method names are welcome.) This change removes the possibility of breaking existing code, too. Some responders brought up the possibility of having a sort of "abstract path" object, but that's a topic worthy of a separate thread. ------------------ The built-in Mutex object should be nestable. Comments were that there are other ways of doing this, and that "sync" and "monitor" exist in the standard distribution, and the RAA has "rmutex". (I didn't know about these). BUT: I think it's good to have a sound set of basic thread support operations in the standard library, expecially since Thread is in the standard library. Ruby actually does a pretty good job of this, since a condition variable and a mutex make up a good foundation for more sophisticated works like "sync" and "monitor". However, I stick with my original suggestion that the fundamental mutex object should be recursive. There is no need in Ruby to have a non-recursive one, so why clutter the language with both recursive and non-recursive versions? I doubt that changing the existing Mutex to be recursive would break any existing code since it would be compatible. (Anyone know of how this might break existing code?) This is a relatively minor change that has little to argue against it. ------------------ A "message" parameter for "abort". Hey -- even Matz liked it! The only instantly pre-approved RCR in this batch. :-) ------------------ Enhanced ObjectSpace finalizer operations Almost no discussion. This is a kind of "big" topic -- I'll work on this more before making any concrete suggestions. Bob