-1

Im having issues with rails with the code

if @turno.chop == res[:department].to_s 

where turno contains strings like ABC1 and department like ABC, im trying to filter if turno its equal of department but i need reduce the string of turno for that. Every time what i try to do that the code dont finish and stuck in other part of code, when i delete the condition, the code works perfectly but dont do the filter.

i tryid to to do like

if @turno.include?(res[:department].to_s)

But appears the same error.

2
  • Please be more accurate. @turno and turno mean different things in Ruby. :department and department are not the same. ABC1 does not mean "ABC1".
    – sawa
    Commented Nov 7, 2018 at 10:24
  • It sounds like the root of your question is how to see if a part of one string exists in another string? I believe include? would work here.
    – Dan
    Commented Nov 7, 2018 at 16:49

2 Answers 2

0

I believe something very similar to this was answered in the stackoverflow.com question. How to check whether a string contains a substring in Ruby?

The include? command sounds like what you should use.

my_string = "abcdefg"
if my_string.include? "cde"
   puts "String includes 'cde'"
end
0

To be more accurate, @turno can contain a string like "ABC1" and res[:department] contains a string with "ABC" i need reduce the string in @turno to the first X characters and compare it with the content of res[:department]

Not the answer you're looking for? Browse other questions tagged or ask your own question.