Class: HTML::Builder
- Inherits:
-
BasicObject
- Defined in:
- lib/html/builder.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(object = nil, namespace = ::HTML) ⇒ Builder
Returns a new instance of Builder.
7
8
9
10
|
# File 'lib/html/builder.rb', line 7
def initialize(object = nil, namespace = ::HTML)
@namespace = namespace
@object = object
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
20
21
22
23
24
|
# File 'lib/html/builder.rb', line 20
def method_missing(method, *args, &block)
class_name = method.to_s.split("_").map(&:capitalize).join
klass = @namespace.const_get(class_name)
klass.new(*args).to_html
end
|
Class Method Details
.build(object = nil, namespace = ::HTML, &block) ⇒ Object
3
4
5
|
# File 'lib/html/builder.rb', line 3
def self.build(object = nil, namespace = ::HTML, &block)
new(object, namespace).build(&block)
end
|
Instance Method Details
#build(&block) ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/html/builder.rb', line 12
def build(&block)
if block.arity > 0
instance_exec(@object, &block)
else
instance_eval(&block)
end
end
|