How do I add empty string as a select option into %w(Mr Ms Mrs Miss)?
I can do ['', 'Mr', 'Ms', 'Mrs', 'Miss'] but I would like to use %w. Thx!
Use unshift it is prepended object to the front:
=> %w(Mr Ms Mrs Miss).unshift ""
#> ["", "Mr", "Ms", "Mrs", "Miss"]
Pretty version without brackets.
Ok for your update:
=> %W(#{} Mr Ms Mrs Miss)
#> ["", "Mr", "Ms", "Mrs", "Miss"]
explain:
%W - allow interpolation%w - not allow interpolation#{} - empty stringTry this:
%w(Mr Ms Mrs Miss).unshift('')
["", "Mr", "Ms", "Mrs", "Miss"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With