summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/erb.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/erb.rb b/lib/erb.rb
index c372f56da8..5c41c37faa 100644
--- a/lib/erb.rb
+++ b/lib/erb.rb
@@ -799,6 +799,7 @@ class ERB
set_eoutvar(compiler, eoutvar)
@src, @enc = *compiler.compile(str)
@filename = nil
+ @lineno = 0
end
##
@@ -815,6 +816,15 @@ class ERB
# is run
attr_accessor :filename
+ # The optional _lineno_ argument passed to Kernel#eval when the ERB code
+ # is run
+ attr_accessor :lineno
+
+ def location=((filename, lineno))
+ @filename = filename
+ @lineno = lineno if lineno
+ end
+
#
# Can be used to set _eoutvar_ as described in ERB::new. It's probably
# easier to just use the constructor though, since calling this method
@@ -844,10 +854,10 @@ class ERB
if @safe_level
proc {
$SAFE = @safe_level
- eval(@src, b, (@filename || '(erb)'), 0)
+ eval(@src, b, (@filename || '(erb)'), @lineno)
}.call
else
- eval(@src, b, (@filename || '(erb)'), 0)
+ eval(@src, b, (@filename || '(erb)'), @lineno)
end
end