Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 6
    This relies on rails, the OP asked for a ruby solution
    – dft
    Commented Nov 13, 2017 at 23:42
  • 3
    That's right, although since a significant proportion of Ruby developers are using Rails, I thought this might be a preferred solution for some due to its clarity and brevity.
    – stwr667
    Commented Nov 15, 2017 at 1:53
  • 1
    See stackoverflow.com/a/4239625/128421. It's in Rails, but is easily accessed from regular Ruby using Rails' Active Support Core Extensions which allow easy cherry-picking of small groups of methods such as only in?. Commented Feb 14, 2020 at 18:53
  • Correct @theTinMan. "cde".in? my_string in pure Ruby yields NoMethodError. But with require 'active_support/core_ext/object/inclusion' it works, which can be loaded either from Rails itself or from the cut-down Active Support Core Extensions.
    – stwr667
    Commented Feb 16, 2020 at 5:47