From a9f3c9da01d721963d05949604ead909aaabbf36 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Mon, 11 Apr 2011 00:52:42 +0800 Subject: Using Object#in? and Object#either? in various places There're a lot of places in Rails source code which make a lot of sense to switching to Object#in? or Object#either? instead of using [].include?. --- railties/lib/rails/commands/application.rb | 4 +++- railties/lib/rails/commands/benchmarker.rb | 4 +++- railties/lib/rails/commands/destroy.rb | 4 +++- railties/lib/rails/commands/generate.rb | 4 +++- railties/lib/rails/commands/profiler.rb | 4 +++- 5 files changed, 15 insertions(+), 5 deletions(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/application.rb b/railties/lib/rails/commands/application.rb index 3b57b925ba..20eb8b485e 100644 --- a/railties/lib/rails/commands/application.rb +++ b/railties/lib/rails/commands/application.rb @@ -1,5 +1,7 @@ require 'rails/version' -if %w(--version -v).include? ARGV.first +require 'active_support/core_ext/object/inclusion' + +if ARGV.first.either?('--version', '-v') puts "Rails #{Rails::VERSION::STRING}" exit(0) end diff --git a/railties/lib/rails/commands/benchmarker.rb b/railties/lib/rails/commands/benchmarker.rb index 0432261802..ecdcccfd8d 100644 --- a/railties/lib/rails/commands/benchmarker.rb +++ b/railties/lib/rails/commands/benchmarker.rb @@ -1,4 +1,6 @@ -if [nil, "-h", "--help"].include?(ARGV.first) +require 'active_support/core_ext/object/inclusion' + +if ARGV.first.either?(nil, "-h", "--help") puts "Usage: rails benchmarker [times] 'Person.expensive_way' 'Person.another_expensive_way' ..." exit 1 end diff --git a/railties/lib/rails/commands/destroy.rb b/railties/lib/rails/commands/destroy.rb index db59cd8ad9..829d29dad7 100644 --- a/railties/lib/rails/commands/destroy.rb +++ b/railties/lib/rails/commands/destroy.rb @@ -1,7 +1,9 @@ require 'rails/generators' +require 'active_support/core_ext/object/inclusion' + Rails::Generators.configure! -if [nil, "-h", "--help"].include?(ARGV.first) +if ARGV.first.either?(nil, "-h", "--help") Rails::Generators.help 'destroy' exit end diff --git a/railties/lib/rails/commands/generate.rb b/railties/lib/rails/commands/generate.rb index 1b3eef504a..bef4c6df14 100644 --- a/railties/lib/rails/commands/generate.rb +++ b/railties/lib/rails/commands/generate.rb @@ -1,7 +1,9 @@ require 'rails/generators' +require 'active_support/core_ext/object/inclusion' + Rails::Generators.configure! -if [nil, "-h", "--help"].include?(ARGV.first) +if ARGV.first.either?(nil, "-h", "--help") Rails::Generators.help 'generate' exit end diff --git a/railties/lib/rails/commands/profiler.rb b/railties/lib/rails/commands/profiler.rb index 6d9717b5cd..baa3baaec0 100644 --- a/railties/lib/rails/commands/profiler.rb +++ b/railties/lib/rails/commands/profiler.rb @@ -1,4 +1,6 @@ -if [nil, "-h", "--help"].include?(ARGV.first) +require 'active_support/core_ext/object/inclusion' + +if ARGV.first.either?(nil, "-h", "--help") $stderr.puts "Usage: rails profiler 'Person.expensive_method(10)' [times] [flat|graph|graph_html]" exit(1) end -- cgit v1.2.3