Sha256: 2106dd84c580e5385b52bbeaa44da6b2f34429f5da8f960adb36c124bf7d9f64

Contents?: true

Size: 989 Bytes

Versions: 11

Compression:

Stored size: 989 Bytes

Contents

# frozen_string_literal: true

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

11 entries across 11 versions & 1 rubygems

Version Path
phlex-1.4.2 lib/phlex/unbuffered.rb
phlex-1.5.3 lib/phlex/unbuffered.rb
phlex-1.6.3 lib/phlex/unbuffered.rb
phlex-1.4.1 lib/phlex/unbuffered.rb
phlex-1.5.2 lib/phlex/unbuffered.rb
phlex-1.6.2 lib/phlex/unbuffered.rb
phlex-1.6.1 lib/phlex/unbuffered.rb
phlex-1.6.0 lib/phlex/unbuffered.rb
phlex-1.5.1 lib/phlex/unbuffered.rb
phlex-1.5.0 lib/phlex/unbuffered.rb
phlex-1.4.0 lib/phlex/unbuffered.rb