rpl.rb/lib/dictionary.rb
2021-12-15 13:32:21 +01:00

38 lines
636 B
Ruby

# frozen_string_literal: true
module Rpl
module Lang
class Dictionary
attr_reader :vars
def initialize
@parser = Parser.new
@words = {}
@vars = {}
end
def add( name, implementation )
@words[ name ] = implementation
end
def add_var( name, implementation )
@vars[ name ] = implementation
end
def remove_var( name )
@vars.delete( name )
end
def remove_all_vars
@vars = {}
end
def lookup( name )
word = @words[ name ]
word ||= @vars[ name ]
word
end
end
end
end