Last active
December 20, 2015 21:49
-
-
Save kachick/6200863 to your computer and use it in GitHub Desktop.
Rubyの最長APIを探してみた ref: http://qiita.com/kachick@github/items/68612dd66bb1cf764265
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
| # find_longest_api_name | |
| # 2013 Kenichi Kamiya | |
| # ruby -v: ruby 2.1.0dev (2013-08-10 trunk 42476) [x86_64-linux] | |
| $VERBOSE = true | |
| class BasicObject | |
| def longest_method_name | |
| (methods(true) | private_methods(true)).reject { |name| | |
| /\Alongest_(?:instance_)?method_name\z/ =~ name }.max_by(&:length) | |
| end | |
| end | |
| class Module | |
| def longest_instance_method_name | |
| (instance_methods(true) | private_instance_methods(true)).reject { |name| | |
| /\Alongest_(?:instance_)?method_name\z/ =~ name }.max_by(&:length) | |
| end | |
| def longest_api(ignore_modules=[]) | |
| apis = [[name, longest_instance_method_name].join('#')] | |
| constants.each do |const_name| | |
| const = const_get const_name | |
| if const.kind_of?(Module) && !ignore_modules.include?(const) | |
| apis << [const.name, longest_method_name].join('.') | |
| ignore_modules << const | |
| apis << const.__send__(__callee__, ignore_modules) | |
| else | |
| apis << [[name, const_name].join("::"), longest_method_name].join('.') | |
| end | |
| end | |
| apis.max_by(&:length) | |
| end | |
| end | |
| p Object.longest_api | |
| #=> Gem::Specification::NONEXISTENT_SPECIFICATION_VERSION.outdated_and_latest_version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment