Sha256: 5eadedb56de29b678542605c39044e302b8030a7eb858fc8fe372650ad274b9c

Contents?: true

Size: 1004 Bytes

Versions: 16

Compression:

Stored size: 1004 Bytes

Contents

# frozen_string_literal: true

# @api private
class Phlex::Unbuffered < BasicObject
	def initialize(object)
		@object = object
	end

	def inspect
		"Unbuffered(#{@object.class.name})[object: #{@object.inspect}]"
	end

	# Borrow some important methods from Object
	define_method :__class__,
		::Object.instance_method(:class)

	define_method :__public_send__,
		::Object.instance_method(:public_send)

	def respond_to_missing?(...)
		@object.respond_to?(...)
	end

	def method_missing(name, *args, **kwargs, &block)
		if @object.respond_to?(name)

			__class__.define_method(name) do |*a, **k, &b|
				@object.capture { @object.public_send(name, *a, **k, &b) }
			end

			# Now we've defined this missing method, we can call it.
			__public_send__(name, *args, **kwargs, &block)
		else
			super
		end
	end

	# Forward some methods to the original underlying method
	def call(...)
		@object.call(...)
	end

	def send(...)
		@object.send(...)
	end

	def public_send(...)
		@object.public_send(...)
	end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
phlex-1.11.0 lib/phlex/unbuffered.rb
phlex-1.10.3 lib/phlex/unbuffered.rb
phlex-1.9.3 lib/phlex/unbuffered.rb
phlex-1.10.2 lib/phlex/unbuffered.rb
phlex-1.7.2 lib/phlex/unbuffered.rb
phlex-1.8.3 lib/phlex/unbuffered.rb
phlex-1.9.2 lib/phlex/unbuffered.rb
phlex-1.10.1 lib/phlex/unbuffered.rb
phlex-1.10.0 lib/phlex/unbuffered.rb
phlex-1.7.1 lib/phlex/unbuffered.rb
phlex-1.8.2 lib/phlex/unbuffered.rb
phlex-1.9.1 lib/phlex/unbuffered.rb
phlex-1.9.0 lib/phlex/unbuffered.rb
phlex-1.8.1 lib/phlex/unbuffered.rb
phlex-1.8.0 lib/phlex/unbuffered.rb
phlex-1.7.0 lib/phlex/unbuffered.rb