Ruby 如何列出模块的已定义方法?

Ruby 如何列出模块的已定义方法?,ruby,Ruby,在这个例子中,我定义了一个方法。 我的问题是:为什么我的method1没有列在最后一条语句的输出中 irb(main):001:0> module Foo irb(main):002:1> def method1 irb(main):003:2> "abc" irb(main):004:2> end irb(main):005:1> end => :method1 irb(main):007:0> Foo.methods => [:<=>

在这个例子中,我定义了一个方法。 我的问题是:为什么我的
method1
没有列在最后一条语句的输出中

irb(main):001:0> module Foo
irb(main):002:1> def method1
irb(main):003:2> "abc"
irb(main):004:2> end
irb(main):005:1> end
=> :method1
irb(main):007:0> Foo.methods
=> [:<=>, :autoload, :autoload?, :<=, :>=, :==, :===, :included_modules, :include?, :name, :ancestors, :attr, :attr_reader, :attr_writer, :attr_accessor, :instance_methods, :public_instance_methods, :protected_instance_methods, :private_instance_methods, :constants, :const_get, :const_set, :const_defined?, :class_variables, :remove_class_variable, :class_variable_get, :class_variable_set, :class_variable_defined?, :public_constant, :freeze, :inspect, :deprecate_constant, :private_constant, :const_missing, :singleton_class?, :prepend, :class_exec, :module_eval, :class_eval, :include, :<, :>, :remove_method, :undef_method, :alias_method, :protected_method_defined?, :module_exec, :method_defined?, :public_method_defined?, :to_s, :define_method, :public_class_method, :private_method_defined?, :private_class_method, :public_instance_method, :instance_method, :instance_variable_set, :instance_variable_defined?, :remove_instance_variable, :instance_of?, :kind_of?, :is_a?, :tap, :instance_variable_get, :public_methods, :instance_variables, :method, :public_method, :define_singleton_method, :singleton_method, :public_send, :extend, :pp, :to_enum, :enum_for, :=~, :!~, :eql?, :respond_to?, :object_id, :send, :display, :nil?, :hash, :class, :singleton_class, :clone, :dup, :yield_self, :itself, :tainted?, :taint, :untrust, :untaint, :trust, :untrusted?, :methods, :frozen?, :singleton_methods, :protected_methods, :private_methods, :!, :equal?, :instance_eval, :instance_exec, :!=, :__id__, :__send__]
irb(main):008:0>
irb(main):001:0>模块Foo
irb(主):002:1>def方法1
irb(主要):003:2>“abc”
irb(主):004:2>结束
irb(主):005:1>结束
=>:方法1
irb(主):007:0>Foo.methods
=> [:,:autoload,:autoload?,:=,:=,:=,:==,:include_模块,:include?,:name,:祖先,:attr,:attr_读取器,:attr_编写器,:attr_访问器,:instance_方法,:public_实例_方法,:protected_实例_方法,:private_实例_方法,:常量,:const_get,:const_集,:const_定义的?,:class_变量,:remove_类_变量,:class_变量表获取、类变量集、类变量定义、公共常量、冻结、检查、弃用常量、私有常量、常量缺失、单例类、前置、类执行、模块评估、类评估、包括、删除方法、取消方法、别名方法、保护方法定义、模块执行、方法定义、公共方法定义的方法、定义的方法、定义的方法、公共的方法、定义的方法、私有的方法、私有的方法、实例的方法、实例的方法、实例的变量集、实例的变量集、实例的变量定义的方法、移除实例的变量、实例的变量、类型的变量、是的、点击、实例的变量获取、公共的方法、实例的变量、方法、公共的_方法,:define_singleton_method,:singleton_method,:public_send,:extend,:pp,:to_enum,:enum_for,:=~,:!~,:eql?,:respond_to?,:object_id,:send,:display,:nil?,:hash,:class,:singleton_class,:clone,:dup,:yield_self,:自身,:污染?,:污染?,:污染?,:不信任,:不信任,:方法,:冻结?,:singleton?,:受保护的方法_方法,:private_methods,:!,:equal?,:instance_eval,:instance_exec,:!=,::\u id_uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
irb(主要):008:0>

因为它是一个实例方法,而不是
Foo
上的方法。您可以通过
找到它。实例\u方法

irb(main):002:0> Foo.instance_methods
=> [:method1]