Define_singleton_method

define_singleton_method use to define singleton method.

example

example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Sayer
  def self.shouts(*words)
    words.each do |word|
      define_singleton_method "shout_#{word}" do
        p word
      end
    end
  end

  shouts :hello, :goodbye
end

Sayer.shout_hello
Sayer.shout_goodbye