Sha256: 5bd193901b09352cc8bb199c95f8957b1e8e511380f3e1a67c6ae179fb064087

Contents?: true

Size: 755 Bytes

Versions: 3

Compression:

Stored size: 755 Bytes

Contents

# invoke call function
def invoke func, *args
	func.respond_to?(:call) ? func.call(*args) : func
end

class Proc
	# send method
	def send symbol, *args_
		Proc.new { |*args|
			self.call(*args).send(symbol, *args_.map{ |it| invoke(it, *args) })
		}
	end

	# call any method
	def method_missing symbol, *args
		send(symbol, *args)
	end
end


# return args[N]
arg1 = Proc.new { |*args| args[0] }
arg2 = Proc.new { |*args| args[1] }


# assemble expr
f = arg1 + arg2

# apply expr
result = f.call(1, 2)
# => 3

# call
# 1. (arg1 + arg2).call(1, 2)
# 2. arg1.send(:+, arg2).call(1, 2)
# 3. arg1.call(1, 2).send(invoke(:+, 1, 2), invoke(arg2, 1, 2))
# 4. arg1.call(1, 2).send(:+, arg2.call(1, 2))
# 5. [1, 2][0].send(:+, [1, 2][1])
# 6. 1.send(:+, 2)
# 7. 3

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
iolite-0.0.3 example/minimal_implement.rb
iolite-0.0.2 example/minimal_implement.rb
iolite-0.0.1 example/minimal_implement.rb