singleton_methods

obj.singleton_methods(all=true) â array
Instance Public methods

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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]
doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.