-
-
Save Sixeight/29957 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# クラスオブジェクトを取得 | |
module Foo | |
class Bar | |
def class_object | |
self.class.to_s.split(/::/).inject(Object) do |c, name| | |
c.const_get(name) | |
end | |
end | |
end | |
end | |
a = Foo::Bar.new.class_object #=> Foo::Bar | |
b = Foo::Bar.new.class #=> Foo::Bar | |
a == b #=> true | |
# だめ? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment