Module: Sinatra::Delegator

Defined in:
lib/sinatra_opal_patches.rb

Overview


  1. Delegator.delegate (upstream base.rb:2113)

Upstream first probes ‘return super(*args, &block) if respond_to? method_name`. Opal’s ‘super` inside `define_method` is hard-wired to the enclosing Ruby method name (’delegate’) at compile time instead of resolving to the dynamically defined method, which breaks top-level ‘get ’/‘ do … end` on the main object. Skip the super probe; the delegator is the sole hook for main, so Delegator.target.send(…) is always the right dispatch.


Class Method Summary collapse

Class Method Details

.delegate(*methods) ⇒ Object



308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/sinatra_opal_patches.rb', line 308

def self.delegate(*methods)
  methods.each do |method_name|
    define_method(method_name) do |*args, &block|
      Delegator.target.send(method_name, *args, &block)
    end
    # Preserve upstream's ruby2_keywords semantics so classic-mode
    # DSL methods that accept `**options` (before / after /
    # configure / helpers / set / ...) forward keyword arguments
    # correctly on Ruby 2.7+ (Copilot review on PR #12).
    ruby2_keywords(method_name) if respond_to?(:ruby2_keywords, true)
    private method_name
  end
end