summaryrefslogtreecommitdiffstats
path: root/lib/blink/function.rb
blob: 9e67b0071d16856424bd424da0a7fe07de7d135f (plain)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/local/bin/ruby -w

# $Id$

require 'blink'
require 'blink/fact'

module Blink
    class Function
        @@functions = Hash.new(nil)

        #---------------------------------------------------------------
        def Function.[](name)
            return @@functions[name]
        end
        #---------------------------------------------------------------

        #---------------------------------------------------------------
        def call(*args)
            @code.call(*args)
        end
        #---------------------------------------------------------------

        #---------------------------------------------------------------
        # we want a 'proc' item instead of a block, so that we can return
        # from it
        def initialize(name,code)
            @name = name
            @code = code

            @@functions[name] = self
        end
        #---------------------------------------------------------------
    end

    Function.new("retrieve", proc { |fact|
        require 'blink/fact'

        return Fact[fact]
    })
end