0

Im new to ruby, and i want to try translate a code python to ruby.What would be a simple, and similarly on this.

print 'it has' if 'ten' in 'tentacle' else 'None'

2 Answers2

10

Ruby String has method include? so it would be like:

print 'tentacle'.include?('ten') ? 'it has' : 'None'
Matt Browne
  • 12,169
  • 4
  • 59
  • 75
Hauleth
  • 22,873
  • 4
  • 61
  • 112
0

If you're using rails, you can use 'in?':

puts 'ten'.in?('tentacle') ? 'it has' : 'None'
A Fader Darkly
  • 3,516
  • 1
  • 22
  • 28