Ask a Question related to Ruby, Design and Development.
-
David A. Black #1
Re: behaviour change of String#gsub(pattern) {|m| ... } for ruby1.9/ruby2?
Hi --
On Fri, 21 Nov 2003, Florian Gross wrote:
I've also just noticed this:> Yukihiro Matsumoto wrote:
>>> > Hi,
> Moin!
>>> > |String#gsub(pattern) {|m| ... }
> > |
> > |It really would be nice to get match data in 'm', but this would surely
> > |break _a lot_ of scripts. How about String#regsub, #regsub!, #resub,
> > |#resub! ? What do others think?
> >
> > Sounds nice. The only reason for the current behavior is that sub
> > predates MatchData. But we have to define migration path.
> I like this, because matz told me I shouldn't be using $1 in the
> gsub-block and there's no way to not do so right now. :)
irb(main):001:0> "abc".gsub(/((x?)abc)/) {|n,m| p n, m}
"abc"
nil
as opposed to:
irb(main):002:0> /((x?)abc)/.match("abc").captures
=> ["abc", ""]
which makes it hard to do, say, downcasing of a capture in #gsub,
without checking it for nil-ness or, as you say, using $1 and friends.
David
--
David A. Black
[email]dblack@wobblini.net[/email]
David A. Black Guest
-
Pattern matching for xx-xx-xx string
Hello, What is the syntax to make sure the user has entered this pattern in a web form: xx-xx-xx where x are integers, for example:... -
behaviour change of String#gsub(pattern) {|m| ... } for ruby 1.9/ruby2?
String#gsub(pattern) {|m| ... } It really would be nice to get match data in 'm', but this would surely break _a lot_ of scripts. How about... -
Bug when rerouting String#gsub with a block using $1?
Moin! This code: class String alias :old_gsub :gsub def gsub(*args, &block) old_gsub(*args, &block) end end -
Change repeater name pattern
When I bind a server control to a repeater it renders one copy of this control for each item in the datasource collection. By doing this it changes... -
gsub(/\s*$/, "") doubling string
Hello, I recently downloaded ruby 1.8.0 p3, (2003-06-23) , and tried it on some code that chopped trailing spaces from a string using gsub(/\s*$/,...



Reply With Quote

