mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Added Object#metaclass
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class Object
|
||||
# Get object's meta (ghost, eigenclass, singleton) class
|
||||
def metaclass
|
||||
class << self
|
||||
self
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user