Skip to content

Instantly share code, notes, and snippets.

@Sixeight
Forked from ukstudio/gist:29937
Created November 28, 2008 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sixeight/29957 to your computer and use it in GitHub Desktop.
Save Sixeight/29957 to your computer and use it in GitHub Desktop.
# クラスオブジェクトを取得
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