diff options
author | Xavier Noria <fxn@hashref.com> | 2012-08-06 00:27:56 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2012-08-06 00:30:02 +0200 |
commit | 447b6a4e678ab1618bdcd130e30c288b0a25297a (patch) | |
tree | 6d9cb3417996517a5b237d3950c25ab32a5db098 /activesupport | |
parent | 6126f02cf903fa206b11d2dc2eeb5f197a29b965 (diff) | |
download | rails-447b6a4e678ab1618bdcd130e30c288b0a25297a.tar.gz rails-447b6a4e678ab1618bdcd130e30c288b0a25297a.tar.bz2 rails-447b6a4e678ab1618bdcd130e30c288b0a25297a.zip |
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.
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/cache/file_store.rb | 7 | ||||
-rw-r--r-- | activesupport/lib/active_support/callbacks.rb | 3 | ||||
-rw-r--r-- | activesupport/lib/active_support/rails.rb | 3 | ||||
-rw-r--r-- | activesupport/lib/active_support/time_with_zone.rb | 3 | ||||
-rw-r--r-- | activesupport/test/transliterate_test.rb | 3 |
5 files changed, 6 insertions, 13 deletions
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 |