Module: Spectre::Delegator

Defined in:
lib/spectre.rb

Constant Summary collapse

@@mappings =
{}

Class Method Summary collapse

Class Method Details

.delegate(*methods, target) ⇒ Object



416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'lib/spectre.rb', line 416

def self.delegate(*methods, target)
  methods.each do |method_name|
    define_method(method_name) do |*args, &block|
      return super(*args, &block) if respond_to? method_name

      target.send(method_name, *args, &block)
    end

    @@mappings[method_name] = target

    private method_name
  end
end

.redirect(method_name, *args, **kwargs, &block) ⇒ Object

Raises:



430
431
432
433
434
435
# File 'lib/spectre.rb', line 430

def self.redirect method_name, *args, **kwargs, &block
  target = @@mappings[method_name] || Kernel
  raise SpectreError.new("no variable or method '#{method_name}' found") unless target.respond_to? method_name

  target.send(method_name, *args, **kwargs, &block)
end