Skip to content

Instantly share code, notes, and snippets.

@memememomo
Created January 8, 2015 15:23
Show Gist options
  • Save memememomo/6d75802ca550800a185a to your computer and use it in GitHub Desktop.
Save memememomo/6d75802ca550800a185a to your computer and use it in GitHub Desktop.
名前空間を取り除いたクラス名を取得する ref: http://qiita.com/uchiko/items/96f5ba10538bce99737a
[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)>
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