読者です 読者をやめる 読者になる 読者になる

methods メソッド(Ruby)

オブジェクトの取れるすべてのメソッドを返します。例えば Integer クラスの取れるメソッドなら、

p 1.methods

でOK。結果は例えば

[:to_s, :inspect, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs,
 :magnitude, :==, :===, :<=>, :>, :>=, :<, :<=, :~, :&, :|, :^, :[], :<<, :>>,
 :to_f, :size, :bit_length, :zero?, :odd?, :even?, :succ, :ord, :integer?, :upto,
 :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, :truncate,
 :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize,
 :singleton_method_added, :coerce, :i, :+@, :eql?, :remainder, :real?, :nonzero?,
 :step, :quo, :to_c, :real, :imaginary, :imag, :abs2, :arg, :angle, :phase,
 :rectangular, :rect, :polar, :conjugate, :conj, :between?, :nil?, :=~, :!~,
 :hash, :class, :singleton_class, :clone, :dup, :taint, :tainted?, :untaint, :untrust,
 :untrusted?, :trust, :freeze, :frozen?, :methods, :singleton_methods, :protected_methods,
 :private_methods, :public_methods, :instance_variables, :instance_variable_get,
 :instance_variable_set, :instance_variable_defined?, :remove_instance_variable,
 :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :extend,
 :display, :method, :public_method, :singleton_method, :define_singleton_method,
 :object_id, :to_enum, :enum_for, :equal?, :!, :!=, :instance_eval, :instance_exec,
 :__send__, :__id__]