-
Notifications
You must be signed in to change notification settings - Fork 0
/
func.rb
28 lines (24 loc) · 854 Bytes
/
func.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class FunctionManager
def initialize
@behaviors = Hash.new
@var_name = Hash.new
prelude_funcs()
end
def add_name(func_name, var_name, func_behabior)
func_name = func_name.strip
var_name = var_name.strip
raise "already defined" unless @var_name[func_name].nil?
@behaviors[func_name] = func_behabior
@var_name[func_name] = var_name
end
def get_name(func_name, value)
raise "not defined" if @var_name[func_name].nil? || @behaviors[func_name].nil?
parser = Parser.new
parser.parse("#{@var_name[func_name]} = #{ value }")
parser.parse(@behaviors[func_name])
end
def prelude_funcs
@behaviors["double"] = "a * a" #lambda{|x| Math.sqrt(x) }
@var_name["double"] = "a" #lambda{|x| Math.sqrt(x) }
end
end