I prefer .lookup() rather than []

This commit is contained in:
Gwenhael Le Moine 2021-12-08 16:38:46 +01:00
parent 50f36fa5c3
commit 464b1c511e
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
4 changed files with 4 additions and 4 deletions

View file

@ -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?

View file

@ -213,7 +213,7 @@ module Rpl
@vars = {}
end
def []( name )
def lookup( name )
word = @words[ name ]
word ||= @vars[ name ]

View file

@ -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]}'" }

View file

@ -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