0

I am newbie in Ruby.

Are there some differences between "string" and 'string' in ruby?

such as

txt_data.gsub("ABC",'') 

and

txt_data.gsub('ABC','')

It seems they are always the same. Are there some cases where we need to use "" and '' selectively?

lei lei
  • 1,753
  • 4
  • 19
  • 44
  • You couls also have written it for instance as `txt_data.gsub(%(ABC),'')`. There are other ways to. Look here for an overview of [Ruby String literals](https://docs.ruby-lang.org/en/2.4.0/syntax/literals_rdoc.html#label-Strings). – user1934428 Feb 10 '21 at 08:47

1 Answers1

2

The difference is, you could interpolate the value when you use "" but you can't when you use ''

See the below example

value=23

a="The value is #{value}"

p a

a='The value is #{value}'

p a

Output

"The value is 23"
"The value is \#{value}"
Rajagopalan
  • 5,465
  • 2
  • 11
  • 29