Rails gem that adds an in? method to Object for a more readable syntax of include?
Mimics the functionality of ActiveSupport 3.1
As a gem (with Bundler)
gem "included-in", :require => "included_in"
As a plugin (Rails 2.3.x)
script/plugin install git://github.com/jaredonline/included-in.git
As a plugin (Rails 3.x)
rails plugin install git://github.com/jaredonline/included-in.git
If you have an object, say a String, “test” and you want to check for its inclusion in an array, [“test”, “jack”, “Three”], without using Included-In your code would look like
str = "test" arr = ["test", "jack", "Three"] if arr.include?("test") # do something... else # do something else... end
It reads “If the array contains this string”, when the real question is, “If the string is included in the array”. The first sentence puts the importance on the array, the second is more concerned with the string. With Included-In it would look like
str = "test" arr = ["test", "jack", "Three"] if str.in?(arr) # do something... else # do something else... end