Class: Hanami::View::Rendering::Scope

Inherits:
LayoutScope
  • Object
show all
Defined in:
lib/hanami/ruby3/hanami/view/rendering/scope.rb

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m_name, *args, **kwargs, &block) ⇒ Object (protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Style/MissingRespondToMissing



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/hanami/ruby3/hanami/view/rendering/scope.rb', line 10

def method_missing(m_name, *args, **kwargs, &block)
  ::Hanami::View::Escape.html(
    # FIXME: this isn't compatible with Hanami 2.0, as it extends a view
    # that we want to be frozen in the future
    #
    # See https://github.com/hanami/view/issues/130#issuecomment-319326236
    if @view.respond_to?(m_name, true)
      @view.__send__ m_name, *args, **kwargs, &block
    elsif @locals.key?(m_name)
      @locals[m_name]
    else
      super
    end
  )
end