Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Using %W I can use %W[a #{} b #{} c], also I can concatenate arrays, but is it possible to create array ['a', '', 'b', '', 'c'] using just %w[]?

share|improve this question
4  
no. %w[] has no way to represent zero-length string as an element. –  dbenhur Oct 19 '12 at 22:29
 
See also stackoverflow.com/questions/4064062/… (there the results contain a space - so it is a similar situation, not the same) –  knut Oct 23 '12 at 20:58
 
@knut: I know about escaping space, but that is not what I want –  tig Oct 24 '12 at 14:09
add comment

2 Answers

You can use

 %w[a \   b \  c].map(&:strip)

,but I think it's not very clean.

share|improve this answer
add comment

A couple of options

%W[a b c #{''} z]

%W[a b c] << " "

(I know this isn't using the %w{} syntax, but for good measure:

'a,b,c,,z'.split(',')

share
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.