phrogz
September 24, 2007, 9:31pm
1
I want to keep running gsub! on a string until it returns nil. How do
you prefer to do this?
true while str.gsub!( … )
while str.gsub!( … ); end
begin
done = !str.gsub!( … )
end until done
begin
made_replacement = str.gsub!( … )
end while made_replacement
…some other way?
phrogz
September 24, 2007, 9:56pm
2
I would use:
while str.gsub!( … ); end
“block … while” is a ‘regretted’ feature
(http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/6768 ).
2007/9/24, Phrogz [email protected] :
phrogz
September 24, 2007, 10:30pm
4
On Sep 24, 2:27 pm, Phrogz [email protected] wrote:
begin
made_replacement = str.gsub!( … )
end while made_replacement
…some other way?
Proper devotion to symmetry leads us to the knowledge that the
sacred bang character must always be paired.
until !str.gsub!( … ); end
phrogz
September 24, 2007, 10:57pm
5
On Sep 24, 2007, at 3:30 PM, Phrogz wrote:
begin
made_replacement = str.gsub!( … )
end while made_replacement
…some other way?
loop { break if str.gsub!(…).nil? }
because it clearly expresses the idea of “keep running gsub! on a
string until it returns nil”.
Regards, Morton
phrogz
September 26, 2007, 11:19am
6
Hi –
On Wed, 26 Sep 2007, William J. wrote:
On Sep 24, 2:27 pm, Phrogz [email protected] wrote:
I want to keep running gsub! on a string until it returns nil. How do
you prefer to do this?
true while str.gsub!( … )
Less prolix:
0 while str.gsub!( … )
I wouldn’t worry; the first version isn’t exactly “War and Peace”
I dislike the throwaway nature of both of them anyway.
David
phrogz
September 26, 2007, 3:08pm
7
On 9/24/07, Phrogz [email protected] wrote:
…some other way?
a = “bccccce”
begin
callcc{|@a|}
a.gsub!(/bc/,“cb”) or raise nil
@a.call
rescue
puts a
end
What else, threads maybe
Robert
phrogz
September 26, 2007, 5:35pm
8
On Sep 24, 2007, at 1:30 PM, Phrogz wrote:
begin
made_replacement = str.gsub!( … )
end while made_replacement
…some other way?
loop{ str.gsub!(re, repl) or break }
a @ http://drawohara.com/
phrogz
September 26, 2007, 11:10am
9
On Sep 24, 2:27 pm, Phrogz [email protected] wrote:
I want to keep running gsub! on a string until it returns nil. How do
you prefer to do this?
true while str.gsub!( … )
Less prolix:
0 while str.gsub!( … )
phrogz
September 26, 2007, 7:00pm
10
On Sep 26, 4:18 am, “David A. Black” [email protected] wrote:
I wouldn’t worry; the first version isn’t exactly “War and Peace”
More terse:
“War & Peace”
phrogz
September 26, 2007, 9:04pm
11
On Thu, 27 Sep 2007 02:00:15 +0900, William J. [email protected]
wrote:
On Sep 26, 4:18 am, “David A. Black” [email protected] wrote:
I wouldn’t worry; the first version isn’t exactly “War and Peace”
More terse:
“War & Peace”
nil while war && peace
-mental
phrogz
September 27, 2007, 1:50am
12
Phrogz wrote:
begin
made_replacement = str.gsub!( … )
end while made_replacement
…some other way?
Having been gotten accustomed to the
while (!expr) {
do_this();
}
way of writing things, I would probably use this in ruby:
until str.gsub!( … ) end
Generally, I write what ever I feel works when I am testing. The try to
refine
it into as clear and concise a manor as I can before I finish the
prototype.
TerryP.