Class: Makanai::TemplateEngine::Erb
- Defined in:
- lib/makanai/template_engine/erb.rb
Instance Attribute Summary collapse
-
#locals ⇒ Object
readonly
Returns the value of attribute locals.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(text:, locals: {}) ⇒ Erb
constructor
A new instance of Erb.
- #result ⇒ Object
Constructor Details
#initialize(text:, locals: {}) ⇒ Erb
Returns a new instance of Erb.
10 11 12 13 14 |
# File 'lib/makanai/template_engine/erb.rb', line 10 def initialize(text:, locals: {}) super() @text = text @locals = locals end |
Instance Attribute Details
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
16 17 18 |
# File 'lib/makanai/template_engine/erb.rb', line 16 def locals @locals end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
16 17 18 |
# File 'lib/makanai/template_engine/erb.rb', line 16 def text @text end |
Instance Method Details
#result ⇒ Object
18 19 20 21 22 23 |
# File 'lib/makanai/template_engine/erb.rb', line 18 def result # NOTE: ERB is need to pass the binding. # So, pass the binding of the object that defined the instance variable. # ref: https://docs.ruby-lang.org/en/2.7.0/ERB.html#method-i-result ERB.new(text).result(Locals.new(locals).self_binding) end |