From: Brian Candler Date: 2010-12-15T03:42:35+09:00 Subject: Re: do your bit for my mental health - how to find the difference between two strings? Iain Barnett wrote in post #968364: > I have a piece of code that doesn't work in a Sinatra app I've been > writing that doesn't work. > > These two forms don't work: > > get '/tweets/:service/' do > > mymethod( params[:service] ) > ... > > get '/tweets/:service/' do > > service = params[:service] > mymethod( service ) > ... > > > This works: > > get '/tweets/:service/' do > > mymethod( 'servicename' ) > > so does this: > > get '/tweets/:service/' do > > service = 'servicename' > mymethod( service ) > > > Using the params[:service] variable then mymethod fails to do what I > expect. If I hard-code the string that it's supposed to represent, it > works. Every way I've examined this variable it looks exactly the same > as a hard-coded version. If you're using ruby 1.9, then there are hidden qualities to strings :-( So I suggest you try: STDERR.puts service.inspect, service.encoding Apart from that, I guess it's possible that there's something else in the program's environment which is different between your two test runs. To minimise these differences, I suggest service = params[:service] service.replace('servicename') # <<<< STDERR.puts service.inspect, service.encoding mymethod( service ) Try running this with the marked line present, and with that line commented out. HTH, Brian. -- Posted via http://www.ruby-forum.com/.