mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added Object#metaclass
This commit is contained in:
parent
89eec91e67
commit
f4f6e57e8c
3 changed files with 17 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue