0

Is it possible somehow in Ruby to write in hash something like this:

"xmlns:soap"

So it will something like

:xmlns:soap

2 Answers 2

5
:"xmlns:soap"

will create a Symbol out of your String, regardless of the containing characters. This is the same as writing:

"xmlns:soap".to_sym
-1

No anything between the double quotes " is a string/ So it will not allowed.

However you can do something like following

{value: :abc} # this will produce {:value=>:abc} 

Note:- above code will work only for Ruby 1.9.3 for older versions write simply

{:value=>:abc} 
1
  • That's not exactly true. You has :'your string' syntax that is syntactic sugar to 'your string'.to_sym and he will get what he want.
    – Hauleth
    Commented Sep 19, 2012 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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