23 Apr 2012, 04:34
Generic-user-small

tlturner77@gmail.com (1 post)

I am very new to ruby and I after some testing I found that on page 44 the code:

["recycler\n"].include?('recycler') ` =>fasle`

is dependent on how quotes are treated . Yes the true answer is false however notice this code:

>> ["recycler\n"].include?("recycler") ` => false » [“recycler\n”].include?(“recycler\n”) => true » [“recycler\n”].include?(‘recycler\n’) ` ` => false ` ` » [“recycler\n”].include?(‘recycler’) ` ` => false `

In this example it looks as if the array is single quotes then argument value must be in single quotes, and if the array is in double quotes the argument value is double quotes. So, as my testing shows if I were to write this as:

>> ["recycler\n"].include?('recycler\n')

The response is false. As a note I wrote this using OSX 10.7.3 is it may have to do with ruby versions??

So, in writing code do I use single quotes for argument values or double quotes?

Thanks,

Tim

  You must be logged in to comment