Adds an #in? method to Object for Rails 2.3, for a more readable syntax of #include?.
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
CHANGELOG
README.rdoc
Rakefile
included-in.gemspec
init.rb

README.rdoc

Included In

Rails gem that adds an in? method to Object for a more readable syntax of include?

Mimics the functionality of ActiveSupport 3.1

Install

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

Usage

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