Added Object#metaclass

This commit is contained in:
Joshua Peek
2008-07-15 21:24:00 -05:00
parent 89eec91e67
commit f4f6e57e8c
3 changed files with 17 additions and 0 deletions

View File

@@ -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 File

@@ -0,0 +1,8 @@
class Object
# Get object's meta (ghost, eigenclass, singleton) class
def metaclass
class << self
self
end
end
end

View File

@@ -173,6 +173,14 @@ class ObjectTests < Test::Unit::TestCase
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