I have this:
sentence.each_char {|char|
   ......
   ......
}
I want this:
sentence.each_char {|char|
   if (char is the last char)
     ......
   end
}
Does anybody know how I can do that?
I have this:
sentence.each_char {|char|
   ......
   ......
}
I want this:
sentence.each_char {|char|
   if (char is the last char)
     ......
   end
}
Does anybody know how I can do that?
length = sentence.length
sentence.each_char.with_index(1){|char, i|
  if i == length
    ...
  end
}
You are looking for 'with_index' option
sentence.each_char.with_index {|char, index|
  if (index == sentence.length-1)
   ......
  end
}