def parse_url(url)
matches = url.match(/\/([\d]{10})/)
return nil unless matches
matches[1]
end
Refactorings
No refactoring yet !
Yury
June 19, 2010, June 19, 2010 16:37, permalink
[\d] same as \d
def parse_url(url)
url[/\/(\d{10})/, 1]
end
Fu86
June 19, 2010, June 19, 2010 18:58, permalink
Thanks a lot. Didn't know this syntax feature.
http://ruby-doc.org/core/classes/String.html#M000771
I want to return nil if nothing matched and the second item in the resulting array if matched. How can i write this more elegant?