提交 f4f6e57e 编写于 作者: J Joshua Peek

Added Object#metaclass

上级 89eec91e
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'
class Object
# Get object's meta (ghost, eigenclass, singleton) class
def metaclass
class << self
self
end
end
end
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册