class ERB::Compiler::PercentLine
:nodoc:
:nodoc:
Good! See also ERB#def_method, ERB#def_module, and ERB#def_class.
klass.new(‘It’).get_it
}
end
#{code}
def get_it
end
@obj = obj
def initialize(obj)
attr_accessor :obj
klass.class_eval %{
klass = Class.new Object
Evaluate using an accessor:
get(‘It’)
extend mod
}
end
#{code}
def get(obj)
mod.module_eval %{
mod = Module.new
Evaluate using an input:
eval code
obj = ‘It’
Evaluate using a variable:
correctly resolve. Using the last example, each of these print ‘Got It!’
The compiled code can be used in any context where the names in the code
== Evaluation
print “Got ”.freeze; print(( obj ).to_s); print “!n”.freeze
#coding:UTF-8
Generates:
puts code
code, enc = compiler.compile(“Got <%= obj %>!n”)
compiler = ERB::Compiler.new(‘<>’)
By default the output is sent to the print method. For example:
_erbout=+”; _erbout.<< “Got ”.freeze; _erbout.<<(( obj ).to_s); _erbout.<< “!n”.freeze; _erbout
#coding:UTF-8
Generates:
puts code
code, enc = compiler.compile(“Got <%= obj %>!n”)
compiler.post_cmd = [“_erbout”]
compiler.insert_cmd = “_erbout.<<”
compiler.put_cmd = “_erbout.<<”
compiler.pre_cmd = [“_erbout=+””]
compiler = ERB::Compiler.new(‘<>’)
ERB#src:
Internally ERB does something like this to generate the code returned by
generated output is handled.
template result when evaluated. ERB::Compiler provides hooks to define how
Compiles ERB templates into Ruby code; the compiled code produces the
ERB::Compiler
–
def initialize(str)
:nodoc:
Good! See also ERB#def_method, ERB#def_module, and ERB#def_class.
klass.new('It').get_it
}
end
#{code}
def get_it
end
@obj = obj
def initialize(obj)
attr_accessor :obj
klass.class_eval %{
klass = Class.new Object
Evaluate using an accessor:
get('It')
extend mod
}
end
#{code}
def get(obj)
mod.module_eval %{
mod = Module.new
Evaluate using an input:
eval code
obj = 'It'
Evaluate using a variable:
correctly resolve. Using the last example, each of these print 'Got It!'
The compiled code can be used in any context where the names in the code
== Evaluation
print "Got ".freeze; print(( obj ).to_s); print "!\n".freeze
#coding:UTF-8
Generates:
puts code
code, enc = compiler.compile("Got <%= obj %>!\n")
compiler = ERB::Compiler.new('<>')
By default the output is sent to the print method. For example:
_erbout=+''; _erbout.<< "Got ".freeze; _erbout.<<(( obj ).to_s); _erbout.<< "!\n".freeze; _erbout
#coding:UTF-8
Generates:
puts code
code, enc = compiler.compile("Got <%= obj %>!\n")
compiler.post_cmd = ["_erbout"]
compiler.insert_cmd = "_erbout.<<"
compiler.put_cmd = "_erbout.<<"
compiler.pre_cmd = ["_erbout=+''"]
compiler = ERB::Compiler.new('<>')
ERB#src:
Internally ERB does something like this to generate the code returned by
generated output is handled.
template result when evaluated. ERB::Compiler provides hooks to define how
Compiles ERB templates into Ruby code; the compiled code produces the
ERB::Compiler
--
def initialize(str) @value = str end