Skip to content

Commit

Permalink
remove Kernel#singleton_class from core_ext as it is present in ruby 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
lest committed Dec 21, 2011
1 parent 2e9eb0a commit a57c644
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
module Kernel
# Returns the object's singleton class.
def singleton_class
class << self
self
end
end unless respond_to?(:singleton_class) # exists in 1.9.2

# class_eval on an object acts like singleton_class.class_eval.
def class_eval(*args, &block)
singleton_class.class_eval(*args, &block)
Expand Down
7 changes: 1 addition & 6 deletions activesupport/test/core_ext/kernel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ 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
Expand Down Expand Up @@ -112,4 +107,4 @@ def self.logger
ensure
Object.send(:remove_const, "Rails")
end
end
end
13 changes: 0 additions & 13 deletions railties/guides/source/active_support_core_extensions.textile
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,6 @@ end

NOTE: Defined in +active_support/core_ext/object/try.rb+.

h4. +singleton_class+

The method +singleton_class+ returns the singleton class of the receiver:

<ruby>
String.singleton_class # => #<Class:String>
String.new.singleton_class # => #<Class:#<String:0x17a1d1c>>
</ruby>

WARNING: Fixnums and symbols have no singleton classes, +singleton_class+ raises +TypeError+ on them. Moreover, the singleton classes of +nil+, +true+, and +false+, are +NilClass+, +TrueClass+, and +FalseClass+, respectively.

NOTE: Defined in +active_support/core_ext/kernel/singleton_class.rb+.

h4. +class_eval(*args, &block)+

You can evaluate code in the context of any object's singleton class using +class_eval+:
Expand Down

0 comments on commit a57c644

Please sign in to comment.