class ParentClass
def super_public_method; end
private
def super_private_methid; end
protected
def super_protected_method; end
end
class ChildClass < ParentClass
def public_method; end
private
def private_method; end
protected
def protected_method; end
end
child = ChildClass.new
def child.singleton_method; end
:singleton_method
p child.methods
p child.public_methods
p child.private_methods
p child.protected_methods
child.singleton_methods
[:singleton_method, :public_method, :protected_method, :super_public_method, :super_protected_method, :pry, :__binding__, :pretty_print, :pretty_print_cycle, :pretty_print_instance_variables, :pretty_print_inspect, :to_json, :instance_of?, :kind_of?, :is_a?, :tap, :public_send, :define_singleton_method, :method, :remove_instance_variable, :instance_variable_set, :extend, :to_enum, :enum_for, :pretty_inspect, :<=>, :===, :=~, :!~, :eql?, :respond_to?, :freeze, :inspect, :object_id, :send, :display, :to_s, :nil?, :hash, :class, :singleton_class, :clone, :dup, :itself, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :frozen?, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variable_get, :instance_variables, :instance_variable_defined?, :!, :==, :!=, :__send__, :equal?, :instance_eval, :instance_exec, :__id__] [:singleton_method, :public_method, :super_public_method, :pry, :__binding__, :pretty_print, :pretty_print_cycle, :pretty_print_instance_variables, :pretty_print_inspect, :to_json, :instance_of?, :kind_of?, :is_a?, :tap, :public_send, :define_singleton_method, :method, :remove_instance_variable, :instance_variable_set, :extend, :to_enum, :enum_for, :pretty_inspect, :<=>, :===, :=~, :!~, :eql?, :respond_to?, :freeze, :inspect, :object_id, :send, :display, :to_s, :nil?, :hash, :class, :singleton_class, :clone, :dup, :itself, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :frozen?, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variable_get, :instance_variables, :instance_variable_defined?, :!, :==, :!=, :__send__, :equal?, :instance_eval, :instance_exec, :__id__] [:private_method, :super_private_methid, :timeout, :DelegateClass, :Digest, :sprintf, :format, :Integer, :Float, :String, :Array, :Hash, :fail, :iterator?, :__method__, :catch, :__dir__, :loop, :global_variables, :throw, :block_given?, :raise, :__callee__, :eval, :Pathname, :Rational, :jj, :trace_var, :untrace_var, :set_trace_func, :at_exit, :Complex, :gem, :select, :caller, :caller_locations, :`, :test, :fork, :exit, :gem_original_require, :JSON, :sleep, :respond_to_missing?, :pp, :j, :load, :exec, :system, :exit!, :abort, :spawn, :syscall, :open, :printf, :print, :putc, :puts, :gets, :readlines, :readline, :initialize_copy, :initialize_clone, :initialize_dup, :srand, :p, :rand, :lambda, :trap, :proc, :require, :require_relative, :autoload, :autoload?, :binding, :URI, :local_variables, :warn, :method_missing, :singleton_method_added, :singleton_method_removed, :singleton_method_undefined, :initialize] [:protected_method, :super_protected_method]
[:singleton_method]
child.methods(false)
[:singleton_method]
module AddSingletonMethodModule
def singleton_method_from_add_singleton_method; end
end
child.extend AddSingletonMethodModule
p child.singleton_methods # == child.singleton_methods(true)
p child.singleton_methods(false)
child.methods(false)
[:singleton_method, :singleton_method_from_add_singleton_method] [:singleton_method]
[:singleton_method]
p child.public_methods(false)
p child.private_methods(false)
child.protected_methods(false)
[:singleton_method, :singleton_method_from_add_singleton_method, :public_method] [:private_method]
[:protected_method]
child.public_methods
[:singleton_method, :singleton_method_from_add_singleton_method, :public_method, :super_public_method, :pry, :__binding__, :pretty_print, :pretty_print_cycle, :pretty_print_instance_variables, :pretty_print_inspect, :to_json, :instance_of?, :kind_of?, :is_a?, :tap, :public_send, :define_singleton_method, :method, :remove_instance_variable, :instance_variable_set, :extend, :to_enum, :enum_for, :pretty_inspect, :<=>, :===, :=~, :!~, :eql?, :respond_to?, :freeze, :inspect, :object_id, :send, :display, :to_s, :nil?, :hash, :class, :singleton_class, :clone, :dup, :itself, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :frozen?, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variable_get, :instance_variables, :instance_variable_defined?, :!, :==, :!=, :__send__, :equal?, :instance_eval, :instance_exec, :__id__]
child.class.public_instance_methods(false)
[:public_method]
次回 10-1-2の ■オブジェクトにメソッドが定義されているかを確認する から再開