[ruby-talk:00396] FromJapan: #2
From:
gotoken@... (GOTO Kentaro)
Date:
1999-06-11 10:11:02 UTC
List:
ruby-talk #396
Hi folks!
How are you? In Japan, June is also known as the rainy season which
called ``Tsuyu''. In this month, it is not only hot but also wet.
Every food go bad in no time. Everyday they bring umbrella. It is very
gloomy... sigh.
Few days ago, I found very nice word in Hikaru UTADA's site:
``The nice thing about rain'', said Eeyore, ``is that it
always stops. Eventually''.
Yeah! It is the truth. Eeyore is a great philosopher, I think.
# Hikaru UTADA is the best selling singer in Japan.
# Eeyore is the famous mule as one of Winnie the Pooh's friends.
Today, I pick up 10 topics -- 4 contrib, 4 reports and 2 Q&A.
Here we go!
______________________________________________________________________
Contibutions
------------
[ruby-list:14900] Rubyfaq-990608
Endo-san put rubyfaq-990608.tar.gz.
It's available via http://www.netlab.co.jp/ruby/FAQ/rubyfaq.html
______________________________________________________________________
[ruby-list:14761] CGI.rb
Aoyama-san put CGI.rb version 0.20. The main change is multipart
form support:
require "CGI"
query = CGI.new
html = CGI.new("html3")
CGI::print{
html.multipart_form{
html.file_field("field_name") +
html.submit
} +
if query.include?("field_name")
html.pre{
"original_filename --> " +
query["field_name"][0].original_filename + "\n" +
"local_path --> " +
query["field_name"][0].local_path + "\n" +
"local_file_size --> " +
query["field_name"][0].stat.size.to_s + "\n" +
"content_type --> " +
query["field_name"][0].content_type + "\n" +
query["field_name"][0].read
}
else
""
end
}
______________________________________________________________________
[ruby-list:14804] telnet.rb(0.20)
Aoyama-san put telnet.rb version 0.20.
It is included now in the next release of ruby.
______________________________________________________________________
[ruby-list:14994] FreeBSD port kit for Ruby/Gtk
Fukuma-san release port kit of Ruby/Gtk for FreeBSD at his site:
ftp://ftp8.big.or.jp/pub/usr8/yasuf/ports/ruby-gtk-0.18.19990611.tar.gz
He also submitted some port kits to http://www.freebsd.org/
ruby-postgres-0.4.1
ruby-readline-1.7.1
irb-0.5.1
______________________________________________________________________
Reports
-------
[ruby-list:14660] Ruby on Be
I tried to compile ruby-1.2.5 on BeOS(Intel.R4). Successfully done it
expect one warning in math.c. But `make test' failed (Segmentation
fault in line 922); nevertheless I'm using with fighting spirit!
It works well till now.
______________________________________________________________________
[ruby-list:14667] [BUG] def foo; foo end; foo
The following raise [BUG] Segmentation fault:
def foo; foo end; foo
on ruby 1.2.5(99/04/13) [i386-djgpp].
[ruby-list:14687] Re: [BUG] def foo; foo end; foo
> Aha! STACK_LEVEL_MAX may be larger if checking frequency is set
> higher.
For the present, please use 0x180000 instead of 0x100000 in main.c.
______________________________________________________________________
[ruby-list:14739] manual bug
In ruby-man-1.x/String.html:
ljust(width)
rjust(width)
center(width)
- Returns right filled, left filled, centered string,
+ Returns left filled, right filled, centered string,
respectively. If the string is longer than width, returns
the string itself without modification.
______________________________________________________________________
Q and A
-------
[ruby-list:14642] Re: archive.rb
Question:
I'm writing archive.rb which manages archive files.
To define methods for each file type, I try mix-in
for an object. But it doesn't work, fail at `include @type'.
Why?
#!/usr/bin/ruby
include FileTest
class Archive
def what_type
raise "file #{@file} not found" unless exist?(@file)
@file[-3,3].downcase == 'lzh' and return Lha
@file[-3,3].downcase == 'tgz' and return Tar
@file[-6,6].downcase == 'tar.gz' and return Tar
`file #{@file}` =~ /lha.+archive/i and return Lha
raise "file #{@file} is not an archive file."
end
def initialize (file)
@file=file
@type=what_type
include @type
end
def print_id
puts "#{name}"
puts "This file is '#{@file}'."
end
def delete_extracted_files
@extracted_files.each { |f| File.unlink(f) if exist?(f) }
end
end
module Lha
def list (file)
`lha l #{file}`.split (/\n/)[2..-3].filter { |l| l[46..-1]}
end
def extract (file)
@extracted_files=`lha xf #{file}`.split (/\n/).filter { |l| l.split[0] }
end
end
module Tar
def list (file)
`tar tzf #{file}`.split (/\n/)
end
def extract (file)
@extracted_files=`tar xzvf #{file}`.split (/\n/)
end
end
Answer:
`include' is for a module/class. Use `extend' to append
features to an object. In this case, just `extend @type'.
The corrected version of this module will be put on the
sample.
______________________________________________________________________
[ruby-list:14746] gsub("'", "\\'")
Question:
What can replace ' by \' ?
I don't understand the result as follows:
% cat gsub.rb
s="'Test"
p s.gsub("'", "\'")
p s.gsub("'", "\\'")
p s.gsub("'", "\\\'")
p s.gsub("'", "\\\\'")
p s.gsub("'", "\\\\\'")
p s.gsub("'", "\\\\\\'")
p s.gsub("'", "\\")
% ruby gsub.rb
"'Test"
"TestTest"
"TestTest"
"\\'Test"
"\\'Test"
"\\TestTest"
"\\Test"
Answer:
I often fall into backslash trap too.
For a quoted string (''), backslash escaped quote (\') and
backslash escaped backslash (\\) would be interpred,
for a double quote string (""), newline (\n) and various
escape sequences. *After* those interpretations gsub
seeks \1 or \&. So, a backslash seems disappeared.
The following illustrates such situation.
gsub("'", "\\'")
gsub ' \' <- interpretation by ruby's lexical analyzer
gsub ' Test <- interpretation by gsub
gsub("'", "\\\'")
gsub ' \' <- interpretation by ruby's lexical analyzer
gsub ' Test <- interpretation by gsub
gsub("'", "\\\\'")
gsub ' \\' <- interpretation by ruby's lexical analyzer
gsub ' \' <- interpretation by gsub
The last one is what you want. All you mistake is
not realize the method `p' prints \ as \\.
Maybe, the following doesn't bother with such problem
p s.gsub("'") { "\\'" }
______________________________________________________________________
-- gotoken
PS. Hokkaido island, whare I live in, doesn't have the rainy season.
It is very comfortable today :)