:~> $ irb
ruby-1.9.2-p0 > :“hello”+‘world’
NoMethodError: undefined method +' for :hello:Symbol from (irb):1 from /home/eugenc/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in ’
ruby-1.9.2-p0 > x = “hello”+‘world’
=> “helloworld”
ruby-1.9.2-p0 > :x
=> :x
ruby-1.9.2-p0 >
In your case ruby converted :‘templates/’ to symbol, then tried to
concatenate string to it, this is because ‘:’ has higher priority then
‘+’ operator. Solution is
According to the Sinatra docs, it must be a symbol. So I would just use
string interpolation:
erb :“templates/#{style}/layout”
Or if you must do things the hard way, you can use the much uglier:
erb (‘templates/’+style+’/layout’).to_sym
Note that when you use string interpolation, you create only one string.
However, when you use this construct:
‘templates/’+style+’/layout’
First, you create the string ‘templates/’ and then the string ‘/layout’,
and then you concatenate them with the style variable, to create a third
string. Therefore, you should prefer string interpolation over string
concatenation.