Browse files

Added Object#metaclass

  • Loading branch information...
1 parent 97ac788 commit 98dd7226fa2fb306008fb5d89e38ac2391453664 @josh josh committed Jul 16, 2008
View
1 activesupport/lib/active_support/core_ext/object.rb
@@ -1,4 +1,5 @@
require 'active_support/core_ext/object/conversions'
require 'active_support/core_ext/object/extending'
require 'active_support/core_ext/object/instance_variables'
+require 'active_support/core_ext/object/metaclass'
require 'active_support/core_ext/object/misc'
View
8 activesupport/lib/active_support/core_ext/object/metaclass.rb
@@ -0,0 +1,8 @@
+class Object
+ # Get object's meta (ghost, eigenclass, singleton) class
+ def metaclass
+ class << self
+ self
+ end
+ end
+end
View
8 activesupport/test/core_ext/object_and_class_ext_test.rb
@@ -173,6 +173,14 @@ def test_duck_typing
assert duck.acts_like?(:time)
assert !duck.acts_like?(:date)
end
+
+ def test_metaclass
+ string = "Hello"
+ string.metaclass.instance_eval do
+ define_method(:foo) { "bar" }
+ end
+ assert_equal "bar", string.foo
+ end
end
class ObjectInstanceVariableTest < Test::Unit::TestCase

0 comments on commit 98dd722

Please sign in to comment.