diff --git a/lib/core/store.rb b/lib/core/store.rb index 20f06de..9c592c7 100644 --- a/lib/core/store.rb +++ b/lib/core/store.rb @@ -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? diff --git a/lib/dictionary.rb b/lib/dictionary.rb index 528f594..7e4e37e 100644 --- a/lib/dictionary.rb +++ b/lib/dictionary.rb @@ -213,7 +213,7 @@ module Rpl @vars = {} end - def []( name ) + def lookup( name ) word = @words[ name ] word ||= @vars[ name ] diff --git a/lib/runner.rb b/lib/runner.rb index 7f064e8..d020b84 100644 --- a/lib/runner.rb +++ b/lib/runner.rb @@ -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]}'" } diff --git a/spec/language_store_spec.rb b/spec/language_store_spec.rb index f672e55..f2026ca 100644 --- a/spec/language_store_spec.rb +++ b/spec/language_store_spec.rb @@ -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