mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
irb/{context,workspace}.rb: use local_variable_set
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63149 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
698407450b
commit
d6dc676d07
3 changed files with 54 additions and 2 deletions
|
@ -262,7 +262,7 @@ module IRB
|
|||
# to #last_value.
|
||||
def set_last_value(value)
|
||||
@last_value = value
|
||||
@workspace.evaluate self, "_ = IRB.CurrentContext.last_value"
|
||||
@workspace.local_variable_set :_, value
|
||||
end
|
||||
|
||||
# Sets the +mode+ of the prompt in this context.
|
||||
|
|
|
@ -71,7 +71,7 @@ EOF
|
|||
end
|
||||
end
|
||||
end
|
||||
eval("_=nil", @binding)
|
||||
@binding.local_variable_set(:_, nil)
|
||||
end
|
||||
|
||||
# The Binding of this workspace
|
||||
|
@ -85,6 +85,14 @@ EOF
|
|||
eval(statements, @binding, file, line)
|
||||
end
|
||||
|
||||
def local_variable_set(name, value)
|
||||
@binding.local_variable_set(name, value)
|
||||
end
|
||||
|
||||
def local_variable_get(name)
|
||||
@binding.local_variable_get(name)
|
||||
end
|
||||
|
||||
# error message manipulator
|
||||
def filter_backtrace(bt)
|
||||
case IRB.conf[:CONTEXT_MODE]
|
||||
|
|
44
test/irb/test_context.rb
Normal file
44
test/irb/test_context.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
# frozen_string_literal: false
|
||||
require 'test/unit'
|
||||
require 'tempfile'
|
||||
require 'irb'
|
||||
require 'rubygems' if defined?(Gem)
|
||||
|
||||
module TestIRB
|
||||
class TestContext < Test::Unit::TestCase
|
||||
class TestInputMethod < ::IRB::InputMethod
|
||||
attr_reader :line, :line_no
|
||||
|
||||
def initialize(list = [])
|
||||
super("test")
|
||||
@line_no = 0
|
||||
@line = list
|
||||
end
|
||||
|
||||
def gets
|
||||
@list[@line_no.tap {@line_no += 1}]
|
||||
end
|
||||
|
||||
def eof?
|
||||
@line_no >= @list.size
|
||||
end
|
||||
end
|
||||
|
||||
def setup
|
||||
IRB.init_config(nil)
|
||||
IRB.conf[:USE_READLINE] = false
|
||||
IRB.conf[:VERBOSE] = false
|
||||
workspace = IRB::WorkSpace.new(Object.new)
|
||||
@context = IRB::Context.new(nil, workspace, TestInputMethod.new)
|
||||
end
|
||||
|
||||
def test_last_value
|
||||
assert_nil(@context.last_value)
|
||||
assert_nil(@context.evaluate('_', 1))
|
||||
obj = Object.new
|
||||
@context.set_last_value(obj)
|
||||
assert_same(obj, @context.last_value)
|
||||
assert_same(obj, @context.evaluate('_', 1))
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue