res = []
path_without_calculation.gsub(/\{(.*?)\}/) {|match|
res << match[1.. match.size-2]
}
res
Refactorings
No refactoring yet !
Chiel Wester
October 22, 2008, October 22, 2008 11:56, permalink
'match.size' part is not required
res = []
path_without_calculation.gsub(/\{(.*?)\}/) {|match|
res << match[1..-2]
}
res
halogenandtoast
October 22, 2008, October 22, 2008 12:24, permalink
I like
res = path_without_calculation.scan(/\{(.*?)\}/)
Dmitry Polushkin
October 22, 2008, October 22, 2008 14:20, permalink
res = path_without_calculation.scan(/\{(.*?)\}/).flatten
Tj Holowaychuk
October 23, 2008, October 23, 2008 22:48, permalink
This is maybe a little nit-picky but we can further this by not being greedy aka: '.*?'
res = path_without_calculation.scan(/\{([^}]+)\}/).flatten
Can this be written shorten?