Skip to content

Instantly share code, notes, and snippets.

@ravelll
Created June 30, 2019 09:15
Show Gist options
  • Save ravelll/581d0a8c88f6a68e24d7c3e2513e9693 to your computer and use it in GitHub Desktop.
Save ravelll/581d0a8c88f6a68e24d7c3e2513e9693 to your computer and use it in GitHub Desktop.
# Classes are from https://docs.ruby-lang.org/ja/2.6.0/library/_builtin.html
classes = [
BasicObject,
Object,
Array,
Binding,
ConditionVariable,
Data,
Dir,
Encoding,
Enumerator,
FalseClass,
Fiber,
Hash,
IO,
File,
MatchData,
Method,
Module,
Class,
Mutex,
NilClass,
Numeric,
Bignum,
Complex,
Fixnum,
Float,
Integer,
Rational,
Proc,
Queue,
Random,
Range,
Regexp,
RubyVM,
String,
Struct,
Symbol,
Thread,
SizedQueue,
ThreadGroup,
Time,
TracePoint,
TrueClass,
UnboundMethod,
]
searchee_method = ARGV[0]
classes_defines_this = []
classes.each do |c|
methods = [c.methods(false), c.instance_methods(false)].flatten.map(&:to_s)
classes_defines_this << c if methods.include?(searchee_method)
end
if classes_defines_this.count > 0
puts "The method \"#{searchee_method}\" is defined at #{classes_defines_this.join(", ")}"
else
puts "No class defines the method \"#{searchee_method}\"."
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment