[Kde-bindings] const_missing method in ruby 1.8
Richard Dale
Richard_Dale at tipitina.demon.co.uk
Tue Aug 5 11:12:31 UTC 2003
On Tuesday 05 August 2003 10:37, Alexander Kellett wrote:
> p.s: maybe this will be interesting to you:
> http://whytheluckystiff.net/articles/2003/08/04/rubyOneEightOh
Yes, it is a good read. I wonder if the matches array would be good way to
implement the argmatch() re's in Qt.rb:
[RCR:139] MatchData#captures
Ruby has excellent support for regular expressions, but we're still working on
giving Ruby it's own angle on them. Matches from a string are returned as
MatchData objects, which can be read as an Array.
text = "name: Jen"
matches = /^(\w+): (\w+)$/.match( text )
# matches[0] = "name: Jen", matches[1] = "name", matches[2] = "Jen"
Enough regular expressions in your code, you might tire of keeping track of
the index for each regular expression group. This RCR mandated
MatchData#captures, which returns an array of the captured groups from a
match.
text = "name: Jen"
matches = /^(\w+): (\w+)$/.match( text )
if matches
key, value = matches.captures
# key = "name", value = "Jen"
end
More information about the Kde-bindings
mailing list