349779c687ad1de3e116f3a5feaf3f92

Can this be written shorten?

res = []
      path_without_calculation.gsub(/\{(.*?)\}/) {|match|
        res << match[1.. match.size-2]
      }
      res

Refactorings

No refactoring yet !

903cbddffa73a7120c1b747a3d46dd32

Chiel Wester

October 22, 2008, October 22, 2008 11:56, permalink

1 rating. Login to rate!

'match.size' part is not required

res = []
    path_without_calculation.gsub(/\{(.*?)\}/) {|match|
        res << match[1..-2]
    }
 res
B066cb3c505933f832faa83238489a89

halogenandtoast

October 22, 2008, October 22, 2008 12:24, permalink

4 ratings. Login to rate!

I like

res = path_without_calculation.scan(/\{(.*?)\}/)
832ed6ace46d61032151f4e1864c057f

Dmitry Polushkin

October 22, 2008, October 22, 2008 14:20, permalink

2 ratings. Login to rate!
res = path_without_calculation.scan(/\{(.*?)\}/).flatten
F1e3ab214a976a39cfd713bc93deb10f

Tj Holowaychuk

October 23, 2008, October 23, 2008 22:48, permalink

No rating. Login to rate!

This is maybe a little nit-picky but we can further this by not being greedy aka: '.*?'

res = path_without_calculation.scan(/\{([^}]+)\}/).flatten

Your refactoring





Format Copy from initial code

or Cancel