summaryrefslogtreecommitdiff
path: root/spec/ruby/core/basicobject
diff options
context:
space:
mode:
authorJean Boussier <byroot@ruby-lang.org>2023-07-13 11:49:28 +0200
committerJean Boussier <jean.boussier@gmail.com>2023-07-24 14:51:20 +0200
commit43a5c191358699fe8b19314763998cb8ca77ed90 (patch)
treeefebe1570ca2c77a66bfb81edeb3f86044e63174 /spec/ruby/core/basicobject
parent14d16bdb1ad8e98d76ec2c43b2c1c412ff707d0b (diff)
Use the caller location as default filename for eval family of methods
[Feature #19755] Before (in /tmp/test.rb): ```ruby Object.class_eval("p __FILE__") # => "(eval)" ``` After: ```ruby Object.class_eval("p __FILE__") # => "(eval at /tmp/test.rb:1)" ``` This makes it much easier to track down generated code in case the author forgot to provide a filename argument.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/8070
Diffstat (limited to 'spec/ruby/core/basicobject')
-rw-r--r--spec/ruby/core/basicobject/instance_eval_spec.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/spec/ruby/core/basicobject/instance_eval_spec.rb b/spec/ruby/core/basicobject/instance_eval_spec.rb
index 699c965171..1f3a43f341 100644
--- a/spec/ruby/core/basicobject/instance_eval_spec.rb
+++ b/spec/ruby/core/basicobject/instance_eval_spec.rb
@@ -84,6 +84,13 @@ describe "BasicObject#instance_eval" do
end
+ ruby_version_is "3.3" do
+ it "uses the caller location as default location" do
+ f = Object.new
+ f.instance_eval("[__FILE__, __LINE__]").should == ["(eval at #{__FILE__}:#{__LINE__})", 1]
+ end
+ end
+
it "has access to receiver's instance variables" do
BasicObjectSpecs::IVars.new.instance_eval { @secret }.should == 99
BasicObjectSpecs::IVars.new.instance_eval("@secret").should == 99