rpl.rb/lib/dictionary.rb

39 lines
636 B
Ruby
Raw Normal View History

2021-12-07 16:09:17 +01:00
# frozen_string_literal: true
2021-11-10 11:01:26 +01:00
module Rpl
2021-12-07 15:50:58 +01:00
module Lang
2021-12-07 16:09:17 +01:00
class Dictionary
attr_reader :vars
2021-12-07 16:09:17 +01:00
def initialize
@parser = Parser.new
@words = {}
@vars = {}
2021-12-07 16:09:17 +01:00
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 )
2021-12-07 16:09:17 +01:00
end
def remove_all_vars
@vars = {}
end
2021-12-08 16:38:46 +01:00
def lookup( name )
word = @words[ name ]
word ||= @vars[ name ]
word
end
2021-11-10 11:01:26 +01:00
end
end
end