From: karan garg Date: 2012-10-08T23:11:55+09:00 Subject: Palindrome error --0016e6d975eea3348b04cb8ccdd9 Content-Type: text/plain; charset=ISO-8859-1 Hi all, I am making a function which should return "true" if the input variable "string" is a palindrome, and returns either "nil" or "false" otherwise. Following is the regex i used: def palindrome?(string) */\w#{string.reverse}$/i =~ /\w{string}$/i * end The above function, however returns error: TypeError: can't convert Regexp to String # your_code.rb:2:in `=~' # your_code.rb:2:in `palindrome?' # spec.rb:7:in `block (2 levels) in ' # ./lib/rspec_runner.rb:36:in `block in run_rspec' # ./lib/rspec_runner.rb:32:in `run_rspec' # ./lib/rspec_runner.rb:23:in `run' # lib/graders/weighted_rspec_grader.rb:6:in `grade!' # ./grade:31:in `
' Please help. And my apologies to take your time with such petty problems -- Regards :) Karan --0016e6d975eea3348b04cb8ccdd9 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi all,
I am making a function which should return &qu= ot;true" if the input variable "string" is a palindrome, and= returns either "nil" or "false" otherwise.

Foll= owing is the regex i used:

def palindrome?(string)
=A0=A0=A0=A0=A0=A0=A0=A0=A0 /\w#{string.r= everse}$/i =3D~ /\w{string}$/i
=A0end

The above function, how= ever returns error:
TypeError:
       can't convert Regexp to String
     # your_code.rb:2:in `=3D~'
     # your_code.rb:2:in `palindrome?'
     # spec.rb:7:in `block (2 levels) in <top (required)>'
     # ./lib/rspec_runner.rb:36:in `block in run_rspec'
     # ./lib/rspec_runner.rb:32:in `run_rspec'
     # ./lib/rspec_runner.rb:23:in `run'
     # lib/graders/weighted_rspec_grader.rb:6:in `grade!'
     # ./grade:31:in `<main>'


Please help.And my apologies to take your time with such petty problems
--
Rega= rds :)
Karan

--0016e6d975eea3348b04cb8ccdd9--