Hi --

On Mon, 16 Dec 2002, Shannon Fang wrote:

> You are absolutely right. I tend to ALWAYS use do ... end. Partly because I
> like pascal better than C, and partly because I don't want too much aliases
> for grammar, to keep my program simple. However, yesterday I found out that:
>
> result=text.gsub(/(regexp)/) do $1.to_i.chr end
>
> won't work (i.e., no return value), but
>
> result=text.gsub(/(regexp)/) { $1.to_i.chr } will...
>
> Is ruby designed to function like that (i.e., different behavior between
> do...end and {}), or is it a little accident?

Either should work fine:

  irb(main):001:0> "abcde".gsub(/(.)/) { $1.upcase }
  "ABCDE"
  irb(main):002:0> "abcde".gsub(/(.)/) do $1.upcase end
  "ABCDE"


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav