Class: Object

Inherits:
BasicObject
Defined in:
lib/singleton_from.rb

Overview

class A singleton_from :start

def initialize(arg1, arg2, &block) p block.call p “Initialize” p arg1 p arg2 end

def start(&block) p block.call p “start” end end

A.start(“1”, “2”) do puts “Hi, everyone… :-)” end

Class Method Summary collapse

Class Method Details

.singleton_from(method_name) ⇒ Object



25
26
27
28
29
30
# File 'lib/singleton_from.rb', line 25

def singleton_from(method_name)
	self.class.send(:define_method, method_name) do |*args, &block|
		instance = self.new(*args, &block)
		instance.send(__method__, &block)
	end
end