I prefer .lookup() rather than []
This commit is contained in:
parent
50f36fa5c3
commit
464b1c511e
4 changed files with 4 additions and 4 deletions
|
@ -27,7 +27,7 @@ module Rpl
|
|||
def rcl( stack, dictionary )
|
||||
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[name]] )
|
||||
|
||||
word = dictionary[ args[0][:value][1..-2] ]
|
||||
word = dictionary.lookup( args[0][:value][1..-2] )
|
||||
|
||||
stack, dictionary = word.call( stack, dictionary, true ) unless word.nil?
|
||||
|
||||
|
|
|
@ -213,7 +213,7 @@ module Rpl
|
|||
@vars = {}
|
||||
end
|
||||
|
||||
def []( name )
|
||||
def lookup( name )
|
||||
word = @words[ name ]
|
||||
word ||= @vars[ name ]
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ module Rpl
|
|||
input.each do |elt|
|
||||
case elt[:type]
|
||||
when :word
|
||||
command = dictionary[ elt[:value] ]
|
||||
command = dictionary.lookup( elt[:value] )
|
||||
|
||||
if command.nil?
|
||||
stack << { type: :name, value: "'#{elt[:value]}'" }
|
||||
|
|
|
@ -25,7 +25,7 @@ class TestLanguageProgram < Test::Unit::TestCase
|
|||
def test_purge
|
||||
lang = Rpl::Language.new
|
||||
lang.run '« 2 dup * » \'quatre\' sto \'quatre\' purge'
|
||||
assert_nil lang.dictionary['quatre']
|
||||
assert_nil lang.dictionary.lookup( 'quatre' )
|
||||
end
|
||||
|
||||
def test_vars
|
||||
|
|
Loading…
Reference in a new issue