Skip to main content
Clean up messy links and improve readability
Source Link
the Tin Man
  • 160.1k
  • 44
  • 218
  • 306

A more succinct idiom than the accepted answer above that's available in RailsRails (from 3.1.0 and above) is .in?.

E.g:

my_string = "abcdefg"
if "cde".in? my_string
  puts "'cde' is in the String."
  puts "i.e. String includes 'cde'"
end

I also think it's more readable.

c.f.See the http://apidock.com/rails/v3.1.0/Object/in%3Fin? documentation for more information.

(Note Note again that it's only available in RailsRails, and not pure Ruby.)

A more succinct idiom than the accepted answer above that's available in Rails (from 3.1.0 and above) is .in?.

E.g:

my_string = "abcdefg"
if "cde".in? my_string
  puts "'cde' is in the String."
  puts "i.e. String includes 'cde'"
end

I also think it's more readable.

c.f. http://apidock.com/rails/v3.1.0/Object/in%3F

(Note that it's only available in Rails, and not pure Ruby.)

A more succinct idiom than the accepted answer above that's available in Rails (from 3.1.0 and above) is .in?:

my_string = "abcdefg"
if "cde".in? my_string
  puts "'cde' is in the String."
  puts "i.e. String includes 'cde'"
end

I also think it's more readable.

See the in? documentation for more information.

Note again that it's only available in Rails, and not pure Ruby.

Improved formatting. Clarifying language/framework.
Source Link
stwr667
  • 1.7k
  • 1
  • 18
  • 34

A more succinct idiom than the accepted answer above that's available in Rails Rails (from 3.1.0 and above) is .in?.

E.g:

my_string = "abcdefg"
if "cde".in? my_string
  puts "'cde' is in the String."
  puts "i.e. String includes 'cde'"
end

I also think it's more readable.

c.f. http://apidock.com/rails/v3.1.0/Object/in%3F

(Note that it's only available in Rails, and not pure Ruby.)

A more succinct idiom than the accepted answer above that's available in Rails (from 3.1.0 and above) is .in?.

E.g:

my_string = "abcdefg"
if "cde".in? my_string
  puts "'cde' is in the String."
  puts "i.e. String includes 'cde'"
end

I also think it's more readable.

c.f. http://apidock.com/rails/v3.1.0/Object/in%3F

A more succinct idiom than the accepted answer above that's available in Rails (from 3.1.0 and above) is .in?.

E.g:

my_string = "abcdefg"
if "cde".in? my_string
  puts "'cde' is in the String."
  puts "i.e. String includes 'cde'"
end

I also think it's more readable.

c.f. http://apidock.com/rails/v3.1.0/Object/in%3F

(Note that it's only available in Rails, and not pure Ruby.)

Source Link
stwr667
  • 1.7k
  • 1
  • 18
  • 34

A more succinct idiom than the accepted answer above that's available in Rails (from 3.1.0 and above) is .in?.

E.g:

my_string = "abcdefg"
if "cde".in? my_string
  puts "'cde' is in the String."
  puts "i.e. String includes 'cde'"
end

I also think it's more readable.

c.f. http://apidock.com/rails/v3.1.0/Object/in%3F