1
0
Fork 0
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:
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