Class: ActionView::BlockHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/block_helpers.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



39
40
41
42
43
44
45
46
# File 'lib/block_helpers.rb', line 39

def method_missing(method, *args, &block)
  if helper.respond_to?(method)
    self.class_eval "def #{method}(*args, &block); helper.send('#{method}', *args, &block); end"
    self.send(method, *args, &block)
  else
    super
  end
end

Class Method Details

.inherited(klass) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/block_helpers.rb', line 8

def self.inherited(klass)
  # Define the helper method
  # e.g. for a class:
  #   class HelloHelper < ActionView::BlockHelper
  #     #.....
  #   end
  #
  # then we define a helper method 'hello_helper'
  #
  method_name = klass.name.split('::').last.underscore
  klass.parent.class_eval %(
    def #{method_name}(*args, &block)
      renderer = #{klass.name}.new(*args)
      renderer.send(:helper=, self)
      if renderer.public_methods(false).include? 'display'
        concat renderer.display(capture(renderer, &block))
      else
        block.call(renderer)
      end
    end
  )
end

Instance Method Details

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/block_helpers.rb', line 31

def respond_to?(method)
  super or helper.respond_to?(method)
end