mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
moves Object#singleton_class to Kernel#singleton_class to match Ruby also there, same for #class_eval to simplify, and adds coverage for class_eval
This commit is contained in:
parent
c140aca361
commit
89978f10af
15 changed files with 25 additions and 19 deletions
|
@ -1,6 +1,6 @@
|
|||
require 'stringio'
|
||||
require 'uri'
|
||||
require 'active_support/core_ext/object/singleton_class'
|
||||
require 'active_support/core_ext/kernel/singleton_class'
|
||||
require 'rack/test'
|
||||
require 'test/unit/assertions'
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ require 'active_support/core_ext/hash/deep_merge'
|
|||
require 'active_support/core_ext/hash/indifferent_access'
|
||||
require 'active_support/core_ext/hash/slice'
|
||||
require 'active_support/core_ext/string/behavior'
|
||||
require 'active_support/core_ext/object/singleton_class'
|
||||
require 'active_support/core_ext/kernel/singleton_class'
|
||||
require 'active_support/core_ext/module/delegation'
|
||||
require 'active_support/core_ext/object/duplicable'
|
||||
require 'active_support/core_ext/object/blank'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'active_support/core_ext/object/singleton_class'
|
||||
require 'active_support/core_ext/kernel/singleton_class'
|
||||
|
||||
module ActiveRecord
|
||||
# Exception that can be raised to stop migrations from going backwards.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'active_support/core_ext/array'
|
||||
require 'active_support/core_ext/hash/except'
|
||||
require 'active_support/core_ext/object/singleton_class'
|
||||
require 'active_support/core_ext/kernel/singleton_class'
|
||||
require 'active_support/core_ext/object/blank'
|
||||
|
||||
module ActiveRecord
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'active_support/core_ext/array/wrap'
|
||||
require 'active_support/core_ext/class/inheritable_attributes'
|
||||
require 'active_support/core_ext/kernel/reporting'
|
||||
require 'active_support/core_ext/object/singleton_class'
|
||||
require 'active_support/core_ext/kernel/singleton_class'
|
||||
|
||||
module ActiveSupport
|
||||
# Callbacks are hooks into the lifecycle of an object that allow you to trigger logic
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'active_support/core_ext/object/singleton_class'
|
||||
require 'active_support/core_ext/kernel/singleton_class'
|
||||
require 'active_support/core_ext/module/delegation'
|
||||
require 'active_support/core_ext/module/remove_method'
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'active_support/core_ext/object/blank'
|
||||
require 'active_support/core_ext/array/extract_options'
|
||||
require 'active_support/core_ext/object/singleton_class'
|
||||
require 'active_support/core_ext/kernel/singleton_class'
|
||||
require 'active_support/core_ext/module/remove_method'
|
||||
|
||||
class Class
|
||||
|
|
|
@ -2,3 +2,4 @@ require 'active_support/core_ext/kernel/reporting'
|
|||
require 'active_support/core_ext/kernel/agnostics'
|
||||
require 'active_support/core_ext/kernel/requires'
|
||||
require 'active_support/core_ext/kernel/debugger'
|
||||
require 'active_support/core_ext/kernel/singleton_class'
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
class Object
|
||||
module Kernel
|
||||
# Returns the object's singleton class.
|
||||
def singleton_class
|
||||
class << self
|
||||
self
|
||||
end
|
||||
end unless respond_to?(:singleton_class)
|
||||
end unless respond_to?(:singleton_class) # exists in 1.9.2
|
||||
|
||||
# class_eval on an object acts like singleton_class_eval.
|
||||
# class_eval on an object acts like singleton_class.class_eval.
|
||||
def class_eval(*args, &block)
|
||||
singleton_class.class_eval(*args, &block)
|
||||
end
|
|
@ -5,7 +5,6 @@ require 'active_support/core_ext/object/try'
|
|||
|
||||
require 'active_support/core_ext/object/conversions'
|
||||
require 'active_support/core_ext/object/instance_variables'
|
||||
require 'active_support/core_ext/object/singleton_class'
|
||||
require 'active_support/core_ext/object/misc'
|
||||
require 'active_support/core_ext/object/extending'
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require 'erb'
|
||||
require 'active_support/core_ext/object/singleton_class'
|
||||
require 'active_support/core_ext/kernel/singleton_class'
|
||||
|
||||
class ERB
|
||||
module Util
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'active_support/core_ext/object/singleton_class'
|
||||
require 'active_support/core_ext/kernel/singleton_class'
|
||||
require 'active_support/core_ext/module/aliasing'
|
||||
|
||||
module ActiveSupport
|
||||
|
|
|
@ -41,6 +41,17 @@ class KernelTest < Test::Unit::TestCase
|
|||
def test_silence_stderr_with_return_value
|
||||
assert_equal 1, silence_stderr { 1 }
|
||||
end
|
||||
|
||||
def test_singleton_class
|
||||
o = Object.new
|
||||
assert_equal class << o; self end, o.singleton_class
|
||||
end
|
||||
|
||||
def test_class_eval
|
||||
o = Object.new
|
||||
class << o; @x = 1; end
|
||||
assert_equal 1, o.class_eval { @x }
|
||||
end
|
||||
end
|
||||
|
||||
class KernelSupressTest < Test::Unit::TestCase
|
||||
|
|
|
@ -118,11 +118,6 @@ class ObjectTests < ActiveSupport::TestCase
|
|||
assert duck.acts_like?(:time)
|
||||
assert !duck.acts_like?(:date)
|
||||
end
|
||||
|
||||
def test_singleton_class
|
||||
o = Object.new
|
||||
assert_equal class << o; self end, o.singleton_class
|
||||
end
|
||||
end
|
||||
|
||||
class ObjectInstanceVariableTest < Test::Unit::TestCase
|
||||
|
|
|
@ -3,7 +3,7 @@ $:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.inc
|
|||
|
||||
require 'active_support'
|
||||
require 'active_support/core_ext/object/blank'
|
||||
require 'active_support/core_ext/object/singleton_class'
|
||||
require 'active_support/core_ext/kernel/singleton_class'
|
||||
require 'active_support/core_ext/array/extract_options'
|
||||
require 'active_support/core_ext/hash/deep_merge'
|
||||
require 'active_support/core_ext/module/attribute_accessors'
|
||||
|
|
Loading…
Reference in a new issue