perhaps a simple question, but we are discussing about whether it better to use this snipper:
if %w(production staging).include?(Rails.env)
versus
if ["production","staging"].include?(Rails.env)
We just want to understand which is the most performant way, ignoring the sytax suggering from Ruby. From what I could on the web, the %w literal seems to be a shorthand to string.split on the provided whitespace string.
But which one is actually the fastest?
p.s : A source for the answer would be appreciated.
Here’s what
%wand%Wdo, taken directly fromparse.y(with ommissions):Considering it’s implemented on the parser level, I wouldn’t worry too much about the performance.