From 447b6a4e678ab1618bdcd130e30c288b0a25297a Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 6 Aug 2012 00:27:56 +0200 Subject: [PATCH] removes usage of Object#in? from the code base (the method remains defined by Active Support) Selecting which key extensions to include in active_support/rails made apparent the systematic usage of Object#in? in the code base. After some discussion in https://github.com/rails/rails/commit/5ea6b0df9a36d033f21b52049426257a4637028d we decided to remove it and use plain Ruby, which seems enough for this particular idiom. In this commit the refactor has been made case by case. Sometimes include? is the natural alternative, others a simple || is the way you actually spell the condition in your head, others a case statement seems more appropriate. I have chosen the one I liked the most in each case. --- .../action_controller/metal/mime_responds.rb | 4 ++-- .../action_dispatch/testing/integration.rb | 2 +- .../test/controller/mime_responds_test.rb | 9 ++++---- actionpack/test/controller/resources_test.rb | 6 +++--- actionpack/test/dispatch/routing_test.rb | 2 +- actionpack/test/template/erb_util_test.rb | 2 +- actionpack/test/template/form_helper_test.rb | 2 +- .../test/template/form_options_helper_test.rb | 2 +- .../test/template/form_tag_helper_test.rb | 2 +- activemodel/lib/active_model/validator.rb | 2 +- .../active_record/associations/association.rb | 2 +- .../associations/has_one_association.rb | 21 +++++++++++-------- activerecord/lib/active_record/inheritance.rb | 2 +- .../lib/active_record/railties/databases.rake | 1 - .../lib/active_record/tasks/database_tasks.rb | 2 +- .../session_migration_generator.rb | 4 ++-- .../cases/associations/join_model_test.rb | 4 ++-- .../test/cases/attribute_methods/read_test.rb | 4 ++-- activerecord/test/cases/defaults_test.rb | 2 +- .../lib/active_support/cache/file_store.rb | 7 +++---- activesupport/lib/active_support/callbacks.rb | 3 +-- activesupport/lib/active_support/rails.rb | 3 --- .../lib/active_support/time_with_zone.rb | 3 +-- activesupport/test/transliterate_test.rb | 3 +-- guides/rails_guides/textile_extensions.rb | 2 -- guides/source/asset_pipeline.textile | 2 +- .../lib/rails/application/configuration.rb | 2 +- railties/lib/rails/commands.rb | 6 ++---- railties/lib/rails/commands/destroy.rb | 3 +-- railties/lib/rails/commands/generate.rb | 3 +-- railties/lib/rails/engine/commands.rb | 4 +--- railties/lib/rails/generators/base.rb | 3 +-- 32 files changed, 53 insertions(+), 66 deletions(-) diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb index 64461c73e0..18ae2c3bfc 100644 --- a/actionpack/lib/action_controller/metal/mime_responds.rb +++ b/actionpack/lib/action_controller/metal/mime_responds.rb @@ -341,9 +341,9 @@ module ActionController #:nodoc: config = self.class.mimes_for_respond_to[mime] if config[:except] - !action.in?(config[:except]) + !config[:except].include?(action) elsif config[:only] - action.in?(config[:only]) + config[:only].include?(action) else true end diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 2b3095a234..ab584abf68 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -345,7 +345,7 @@ module ActionDispatch define_method(method) do |*args| reset! unless integration_session # reset the html_document variable, but only for new get/post calls - @html_document = nil unless method.in?(["cookies", "assigns"]) + @html_document = nil unless method == 'cookies' || method == 'assigns' integration_session.__send__(method, *args).tap do copy_session_variables! end diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index 6f9dd44e21..b21d35c846 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -151,10 +151,11 @@ class RespondToController < ActionController::Base protected def set_layout - if action_name.in?(["all_types_with_layout", "iphone_with_html_response_type"]) - "respond_to/layouts/standard" - elsif action_name == "iphone_with_html_response_type_without_layout" - "respond_to/layouts/missing" + case action_name + when "all_types_with_layout", "iphone_with_html_response_type" + "respond_to/layouts/standard" + when "iphone_with_html_response_type_without_layout" + "respond_to/layouts/missing" end end end diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index c7c367f18a..236e16c68e 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -1307,7 +1307,7 @@ class ResourcesTest < ActionController::TestCase def assert_resource_methods(expected, resource, action_method, method) assert_equal expected.length, resource.send("#{action_method}_methods")[method].size, "#{resource.send("#{action_method}_methods")[method].inspect}" expected.each do |action| - assert action.in?(resource.send("#{action_method}_methods")[method]) + assert resource.send("#{action_method}_methods")[method].include?(action) "#{method} not in #{action_method} methods: #{resource.send("#{action_method}_methods")[method].inspect}" end end @@ -1344,9 +1344,9 @@ class ResourcesTest < ActionController::TestCase options = options.merge(:action => action.to_s) path_options = { :path => path, :method => method } - if action.in?(Array(allowed)) + if Array(allowed).include?(action) assert_recognizes options, path_options - elsif action.in?(Array(not_allowed)) + elsif Array(not_allowed).include?(action) assert_not_recognizes options, path_options end end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index d0308b0e74..b029131ad8 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -511,7 +511,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest resources :todos, :id => /\d+/ end - scope '/countries/:country', :constraints => lambda { |params, req| params[:country].in?(["all", "France"]) } do + scope '/countries/:country', :constraints => lambda { |params, req| %w(all France).include?(params[:country]) } do get '/', :to => 'countries#index' get '/cities', :to => 'countries#cities' end diff --git a/actionpack/test/template/erb_util_test.rb b/actionpack/test/template/erb_util_test.rb index 4132c8ca04..f1cb920963 100644 --- a/actionpack/test/template/erb_util_test.rb +++ b/actionpack/test/template/erb_util_test.rb @@ -39,7 +39,7 @@ class ErbUtilTest < ActiveSupport::TestCase def test_rest_in_ascii (0..127).to_a.map {|int| int.chr }.each do |chr| - next if chr.in?('&"<>\'') + next if %('"&<>).include?(chr) assert_equal chr, html_escape(chr) end end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index ab22dbfa44..a20a68c1b2 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -2659,7 +2659,7 @@ class FormHelperTest < ActionView::TestCase def hidden_fields(method = nil) txt = %{
} txt << %{} - if method && !method.to_s.in?(['get', 'post']) + if method && !%w(get post).include?(method.to_s) txt << %{} end txt << %{
} diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 66a572e719..682ffdcc18 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -82,7 +82,7 @@ class FormOptionsHelperTest < ActionView::TestCase def test_collection_options_with_proc_for_disabled assert_dom_equal( "\n\n", - options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => lambda{|p| p.author_name.in?(["Babe", "Cabe"]) }) + options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => lambda {|p| %w(Babe Cabe).include?(p.author_name)}) ) end diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index dcae5b2352..9a85b1b553 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -15,7 +15,7 @@ class FormTagHelperTest < ActionView::TestCase txt = %{
} txt << %{} - if method && !method.to_s.in?(['get','post']) + if method && !%w(get post).include?(method.to_s) txt << %{} end txt << %{
} diff --git a/activemodel/lib/active_model/validator.rb b/activemodel/lib/active_model/validator.rb index 87e4319421..85aec00f25 100644 --- a/activemodel/lib/active_model/validator.rb +++ b/activemodel/lib/active_model/validator.rb @@ -65,7 +65,7 @@ module ActiveModel # # class TitleValidator < ActiveModel::EachValidator # def validate_each(record, attribute, value) - # record.errors.add attribute, 'must be Mr. Mrs. or Dr.' unless value.in?(['Mr.', 'Mrs.', 'Dr.']) + # record.errors.add attribute, 'must be Mr., Mrs., or Dr.' unless %w(Mr. Mrs. Dr.).include?(value) # end # end # diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index 4db7038d2e..9f47e7e631 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -176,7 +176,7 @@ module ActiveRecord def creation_attributes attributes = {} - if reflection.macro.in?([:has_one, :has_many]) && !options[:through] + if (reflection.macro == :has_one || reflection.macro == :has_many) && !options[:through] attributes[reflection.foreign_key] = owner[reflection.active_record_primary_key] if reflection.options[:as] diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb index c5aed6e26a..191c4e8e39 100644 --- a/activerecord/lib/active_record/associations/has_one_association.rb +++ b/activerecord/lib/active_record/associations/has_one_association.rb @@ -51,16 +51,19 @@ module ActiveRecord end def remove_target!(method) - if method.in?([:delete, :destroy]) - target.send(method) - else - nullify_owner_attributes(target) + case method + when :delete + target.delete + when :destroy + target.destroy + else + nullify_owner_attributes(target) - if target.persisted? && owner.persisted? && !target.save - set_owner_attributes(target) - raise RecordNotSaved, "Failed to remove the existing associated #{reflection.name}. " + - "The record failed to save when after its foreign key was set to nil." - end + if target.persisted? && owner.persisted? && !target.save + set_owner_attributes(target) + raise RecordNotSaved, "Failed to remove the existing associated #{reflection.name}. " + + "The record failed to save when after its foreign key was set to nil." + end end end diff --git a/activerecord/lib/active_record/inheritance.rb b/activerecord/lib/active_record/inheritance.rb index 7d759c1048..04fff99a6e 100644 --- a/activerecord/lib/active_record/inheritance.rb +++ b/activerecord/lib/active_record/inheritance.rb @@ -55,7 +55,7 @@ module ActiveRecord end sup = active_record_super - if sup.in?([Base, Model]) || sup.abstract_class? + if sup == Base || sup == Model || sup.abstract_class? self else sup.base_class diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index 6bb0c39b79..e0659700b6 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -1,4 +1,3 @@ -require 'active_support/core_ext/object/inclusion' require 'active_record' db_namespace = namespace :db do diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb index fb3dfc2730..b41cc68b6a 100644 --- a/activerecord/lib/active_record/tasks/database_tasks.rb +++ b/activerecord/lib/active_record/tasks/database_tasks.rb @@ -115,7 +115,7 @@ module ActiveRecord end def local_database?(configuration) - configuration['host'].in?(LOCAL_HOSTS) || configuration['host'].blank? + configuration['host'].blank? || LOCAL_HOSTS.include?(configuration['host']) end end end diff --git a/activerecord/lib/rails/generators/active_record/session_migration/session_migration_generator.rb b/activerecord/lib/rails/generators/active_record/session_migration/session_migration_generator.rb index a976571dee..75aee4f408 100644 --- a/activerecord/lib/rails/generators/active_record/session_migration/session_migration_generator.rb +++ b/activerecord/lib/rails/generators/active_record/session_migration/session_migration_generator.rb @@ -13,8 +13,8 @@ module ActiveRecord def session_table_name current_table_name = ActiveRecord::SessionStore::Session.table_name - if current_table_name.in?(["sessions", "session"]) - current_table_name = (ActiveRecord::Base.pluralize_table_names ? 'session'.pluralize : 'session') + if current_table_name == 'session' || current_table_name == 'sessions' + current_table_name = ActiveRecord::Base.pluralize_table_names ? 'sessions' : 'session' end current_table_name end diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb index d4b7960047..3cea20527e 100644 --- a/activerecord/test/cases/associations/join_model_test.rb +++ b/activerecord/test/cases/associations/join_model_test.rb @@ -453,7 +453,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase assert saved_post.tags.include?(new_tag) assert new_tag.persisted? - assert new_tag.in?(saved_post.reload.tags(true)) + assert saved_post.reload.tags(true).include?(new_tag) new_post = Post.new(:title => "Association replacmenet works!", :body => "You best believe it.") @@ -466,7 +466,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase new_post.save! assert new_post.persisted? - assert saved_tag.in?(new_post.reload.tags(true)) + assert new_post.reload.tags(true).include?(saved_tag) assert !posts(:thinking).tags.build.persisted? assert !posts(:thinking).tags.new.persisted? diff --git a/activerecord/test/cases/attribute_methods/read_test.rb b/activerecord/test/cases/attribute_methods/read_test.rb index 55d45d9d93..da5d9d8c2a 100644 --- a/activerecord/test/cases/attribute_methods/read_test.rb +++ b/activerecord/test/cases/attribute_methods/read_test.rb @@ -47,13 +47,13 @@ module ActiveRecord instance = @klass.new @klass.column_names.each do |name| - assert !name.in?(instance.methods.map(&:to_s)) + assert !instance.methods.map(&:to_s).include?(name) end @klass.define_attribute_methods @klass.column_names.each do |name| - assert name.in?(instance.methods.map(&:to_s)), "#{name} is not defined" + assert instance.methods.map(&:to_s).include?(name), "#{name} is not defined" end end diff --git a/activerecord/test/cases/defaults_test.rb b/activerecord/test/cases/defaults_test.rb index 81c5850a47..deaf5252db 100644 --- a/activerecord/test/cases/defaults_test.rb +++ b/activerecord/test/cases/defaults_test.rb @@ -94,7 +94,7 @@ if current_adapter?(:MysqlAdapter) or current_adapter?(:Mysql2Adapter) assert_equal 0, klass.columns_hash['zero'].default assert !klass.columns_hash['zero'].null # 0 in MySQL 4, nil in 5. - assert klass.columns_hash['omit'].default.in?([0, nil]) + assert [0, nil].include?(klass.columns_hash['omit'].default) assert !klass.columns_hash['omit'].null assert_raise(ActiveRecord::StatementInvalid) { klass.create! } diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index 5be63af342..2c1ad60d44 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -1,6 +1,5 @@ require 'active_support/core_ext/file/atomic' require 'active_support/core_ext/string/conversions' -require 'active_support/core_ext/object/inclusion' require 'uri/common' module ActiveSupport @@ -23,7 +22,7 @@ module ActiveSupport end def clear(options = nil) - root_dirs = Dir.entries(cache_path).reject{|f| f.in?(EXCLUDED_DIRS + [".gitkeep"])} + root_dirs = Dir.entries(cache_path).reject {|f| (EXCLUDED_DIRS + [".gitkeep"]).include?(f)} FileUtils.rm_r(root_dirs.collect{|f| File.join(cache_path, f)}) end @@ -151,7 +150,7 @@ module ActiveSupport # Delete empty directories in the cache. def delete_empty_directories(dir) return if dir == cache_path - if Dir.entries(dir).reject{|f| f.in?(EXCLUDED_DIRS)}.empty? + if Dir.entries(dir).reject {|f| EXCLUDED_DIRS.include?(f)}.empty? File.delete(dir) rescue nil delete_empty_directories(File.dirname(dir)) end @@ -165,7 +164,7 @@ module ActiveSupport def search_dir(dir, &callback) return if !File.exist?(dir) Dir.foreach(dir) do |d| - next if d.in?(EXCLUDED_DIRS) + next if EXCLUDED_DIRS.include?(d) name = File.join(dir, d) if File.directory?(name) search_dir(name, &callback) diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 8f79334159..3f7d0e401a 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -3,7 +3,6 @@ require 'active_support/descendants_tracker' require 'active_support/core_ext/class/attribute' require 'active_support/core_ext/kernel/reporting' require 'active_support/core_ext/kernel/singleton_class' -require 'active_support/core_ext/object/inclusion' module ActiveSupport # \Callbacks are code hooks that are run at key points in an object's lifecycle. @@ -353,7 +352,7 @@ module ActiveSupport # CallbackChain. # def __update_callbacks(name, filters = [], block = nil) #:nodoc: - type = filters.first.in?([:before, :after, :around]) ? filters.shift : :before + type = [:before, :after, :around].include?(filters.first) ? filters.shift : :before options = filters.last.is_a?(Hash) ? filters.pop : {} filters.unshift(block) if block diff --git a/activesupport/lib/active_support/rails.rb b/activesupport/lib/active_support/rails.rb index 933c6e6136..b05c3ff126 100644 --- a/activesupport/lib/active_support/rails.rb +++ b/activesupport/lib/active_support/rails.rb @@ -11,9 +11,6 @@ # Defines Object#blank? and Object#present?. require 'active_support/core_ext/object/blank' -# Defines Object#in?. -require 'active_support/core_ext/object/inclusion' - # Rails own autoload, eager_load, etc. require 'active_support/dependencies/autoload' diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 451520ac5c..93c2d614f5 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -1,6 +1,5 @@ require 'active_support/values/time_zone' require 'active_support/core_ext/object/acts_like' -require 'active_support/core_ext/object/inclusion' module ActiveSupport # A Time-like class that can represent a time in any time zone. Necessary because standard Ruby Time instances are @@ -339,7 +338,7 @@ module ActiveSupport end def duration_of_variable_length?(obj) - ActiveSupport::Duration === obj && obj.parts.any? {|p| p[0].in?([:years, :months, :days]) } + ActiveSupport::Duration === obj && obj.parts.any? {|p| [:years, :months, :days].include?(p[0]) } end def wrap_with_time_zone(time) diff --git a/activesupport/test/transliterate_test.rb b/activesupport/test/transliterate_test.rb index b7076e9e58..b5d8142458 100644 --- a/activesupport/test/transliterate_test.rb +++ b/activesupport/test/transliterate_test.rb @@ -1,7 +1,6 @@ # encoding: utf-8 require 'abstract_unit' require 'active_support/inflector/transliterate' -require 'active_support/core_ext/object/inclusion' class TransliterateTest < ActiveSupport::TestCase @@ -16,7 +15,7 @@ class TransliterateTest < ActiveSupport::TestCase # create string with range of Unicode"s western characters with # diacritics, excluding the division and multiplication signs which for # some reason or other are floating in the middle of all the letters. - string = (0xC0..0x17E).to_a.reject {|c| c.in?([0xD7, 0xF7])}.pack("U*") + string = (0xC0..0x17E).to_a.reject {|c| [0xD7, 0xF7].include?(c)}.pack("U*") string.each_char do |char| assert_match %r{^[a-zA-Z']*$}, ActiveSupport::Inflector.transliterate(string) end diff --git a/guides/rails_guides/textile_extensions.rb b/guides/rails_guides/textile_extensions.rb index 0a002a785f..1faddd4ca0 100644 --- a/guides/rails_guides/textile_extensions.rb +++ b/guides/rails_guides/textile_extensions.rb @@ -1,5 +1,3 @@ -require 'active_support/core_ext/object/inclusion' - module RedCloth::Formatters::HTML def emdash(opts) "--" diff --git a/guides/source/asset_pipeline.textile b/guides/source/asset_pipeline.textile index 42b5d102e7..8fec109951 100644 --- a/guides/source/asset_pipeline.textile +++ b/guides/source/asset_pipeline.textile @@ -432,7 +432,7 @@ NOTE. If you are precompiling your assets locally, you can use +bundle install - The default matcher for compiling files includes +application.js+, +application.css+ and all non-JS/CSS files (this will include all image assets automatically): -[ Proc.new{ |path| !File.extname(path).in?(['.js', '.css']) }, /application.(css|js)$/ ] +[ Proc.new{ |path| !%w(.js .css).include?(File.extname(path)) }, /application.(css|js)$/ ] NOTE. The matcher (and other members of the precompile array; see below) is applied to final compiled file names. This means that anything that compiles to JS/CSS is excluded, as well as raw JS/CSS files; for example, +.coffee+ and +.scss+ files are *not* automatically included as they compile to JS/CSS. diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 9521805778..2b36cc9d0d 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -49,7 +49,7 @@ module Rails @assets = ActiveSupport::OrderedOptions.new @assets.enabled = false @assets.paths = [] - @assets.precompile = [ Proc.new{ |path| !File.extname(path).in?(['.js', '.css']) }, + @assets.precompile = [ Proc.new { |path| !%w(.js .css).include?(File.extname(path)) }, /(?:\/|\\|\A)application\.(css|js)$/ ] @assets.prefix = "/assets" @assets.version = '' diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb index 8816387d34..9c5dc8f188 100644 --- a/railties/lib/rails/commands.rb +++ b/railties/lib/rails/commands.rb @@ -1,5 +1,3 @@ -require 'active_support/core_ext/object/inclusion' - ARGV << '--help' if ARGV.empty? aliases = { @@ -71,7 +69,7 @@ when 'application', 'runner' require "rails/commands/#{command}" when 'new' - if ARGV.first.in?(['-h', '--help']) + if %w(-h --help).include?(ARGV.first) require 'rails/commands/application' else puts "Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first.\n" @@ -84,7 +82,7 @@ when '--version', '-v' require 'rails/commands/application' else - puts "Error: Command not recognized" unless command.in?(['-h', '--help']) + puts "Error: Command not recognized" unless %w(-h --help).include?(command) puts <<-EOT Usage: rails COMMAND [ARGS] diff --git a/railties/lib/rails/commands/destroy.rb b/railties/lib/rails/commands/destroy.rb index ae354eca97..9023c61bf2 100644 --- a/railties/lib/rails/commands/destroy.rb +++ b/railties/lib/rails/commands/destroy.rb @@ -1,7 +1,6 @@ require 'rails/generators' -require 'active_support/core_ext/object/inclusion' -if ARGV.first.in?([nil, "-h", "--help"]) +if [nil, "-h", "--help"].include?(ARGV.first) Rails::Generators.help 'destroy' exit end diff --git a/railties/lib/rails/commands/generate.rb b/railties/lib/rails/commands/generate.rb index 1fb2d98834..9f13cb0513 100644 --- a/railties/lib/rails/commands/generate.rb +++ b/railties/lib/rails/commands/generate.rb @@ -1,7 +1,6 @@ require 'rails/generators' -require 'active_support/core_ext/object/inclusion' -if ARGV.first.in?([nil, "-h", "--help"]) +if [nil, "-h", "--help"].include?(ARGV.first) Rails::Generators.help 'generate' exit end diff --git a/railties/lib/rails/engine/commands.rb b/railties/lib/rails/engine/commands.rb index ffbc0b4bd6..072d16291b 100644 --- a/railties/lib/rails/engine/commands.rb +++ b/railties/lib/rails/engine/commands.rb @@ -1,5 +1,3 @@ -require 'active_support/core_ext/object/inclusion' - ARGV << '--help' if ARGV.empty? aliases = { @@ -25,7 +23,7 @@ when '--version', '-v' require 'rails/commands/application' else - puts "Error: Command not recognized" unless command.in?(['-h', '--help']) + puts "Error: Command not recognized" unless %w(-h --help).include?(command) puts <<-EOT Usage: rails COMMAND [ARGS] diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index a49a1724c5..a3f8ebf476 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -8,7 +8,6 @@ rescue LoadError end require 'rails/generators/actions' -require 'active_support/core_ext/object/inclusion' module Rails module Generators @@ -171,7 +170,7 @@ module Rails names.each do |name| defaults = if options[:type] == :boolean { } - elsif default_value_for_option(name, options).in?([true, false]) + elsif [true, false].include?(default_value_for_option(name, options)) { :banner => "" } else { :desc => "#{name.to_s.humanize} to be invoked", :banner => "NAME" }