0

I have e.g. r = "\t" and a = "thisisabigbad\wolf"

How can I prevent ruby from auto escaping my string and also count the \ at the same time?

a.count r #=> this should return 2 instead of 0

I wish to do a.count and receive 2

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
Charlie
  • 13
  • 2

1 Answers1

0

You can use single quotes:

[17] pry(main)> r = '\t'
=> "\\t"
[18] pry(main)> r.size
=> 2
[20] pry(main)> a = 'thisisabigbad\wolf'
=> "thisisabigbad\\wolf"
[21] pry(main)> a.size
=> 18
Anthony
  • 15,435
  • 4
  • 39
  • 69