summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-12 10:31:47 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-12 10:31:47 +0000
commite82f4195d49b730a48031738694391dbb3e41091 (patch)
treea3761ebf102d08a532532674de1611b6e9e603d3 /lib
parent4d3677e14bf0adf8ddeabfff395831b8e032209c (diff)
erb: lineno and location setters
* lib/erb.rb (ERB#lineno): accessor for line number to eval. * lib/erb.rb (ERB#location=): setter of file name and line number. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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