-
-
Save memememomo/6d75802ca550800a185a to your computer and use it in GitHub Desktop.
名前空間を取り除いたクラス名を取得する ref: http://qiita.com/uchiko/items/96f5ba10538bce99737a
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
[1] pry(main)> show-source Class.class_name | |
From: /Users/uchiko/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/yard-0.8.7.6/lib/yard/core_ext/module.rb @ line 7: | |
Owner: Module | |
Visibility: public | |
Number of lines: 3 | |
def class_name | |
name.split("::").last | |
end | |
[2] pry(main)> |
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 Hoge | |
class Fuga | |
def name | |
self.fullname.split('::').last | |
end | |
def fullname | |
self.class.to_s | |
end | |
end | |
end | |
m = Hoge::Fuga.new | |
p m.name #=> "Fuga" | |
p m.fullname #=> "Hoge::Fuga" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment