Skip to content
instance method

Object#singleton_methods

(?::boolish all) -> ::Array[::Symbol]
obj.singleton_methods(all=true) → array

Returns an array of the names of singleton methods for obj. If the optional all parameter is true, the list will include methods in modules included in obj. Only public and protected singleton methods are returned.

Example
module Other
  def three() end
end

class Single
  def Single.four() end
end

a = Single.new

def a.one()
end

class << a
  include Other
  def two()
  end
end

Single.singleton_methods    #=> [:four]
a.singleton_methods(false)  #=> [:two, :one]
a.singleton_methods         #=> [:two, :one, :three]
See also #singleton_method #to_enum #singleton_class #to_s also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0