Class: TdlSpace::DefArrayChain

Inherits:
Object
  • Object
show all
Defined in:
lib/tdl/sdlmodule/sdlmodule_arraychain.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(belong_to_module) ⇒ DefArrayChain

Returns a new instance of DefArrayChain.



18
19
20
21
# File 'lib/tdl/sdlmodule/sdlmodule_arraychain.rb', line 18

def initialize(belong_to_module)
    @chain = []
    @belong_to_module = belong_to_module
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/tdl/sdlmodule/sdlmodule_arraychain.rb', line 56

def method_missing(name,*args,&block)
    ClassHDL::AssignDefOpertor.with_rollback_opertors(:old) do 
        if name !~ /\w+/
            super 
        end

        if args && args.any? && args[0].is_a?(Hash)
            args[0].each do |key,value|
                self.instance_variable_set("@#{key}",value)
            end
        end

        self - name
    end
end

Instance Attribute Details

#belong_to_moduleObject

Returns the value of attribute belong_to_module.



16
17
18
# File 'lib/tdl/sdlmodule/sdlmodule_arraychain.rb', line 16

def belong_to_module
  @belong_to_module
end

#chainObject

Returns the value of attribute chain.



16
17
18
# File 'lib/tdl/sdlmodule/sdlmodule_arraychain.rb', line 16

def chain
  @chain
end

Instance Method Details

#-(name) ⇒ Object

Raises:



32
33
34
35
36
37
# File 'lib/tdl/sdlmodule/sdlmodule_arraychain.rb', line 32

def -(name)
    raise TdlError.new(" Base Class cant define anything!!!")
    # if name.is_a? StringBandItegration
    #     raise TDLError.new("简化定义模式不允许传入 StringBandItegration 类型")
    # end
end

#[](*a) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/tdl/sdlmodule/sdlmodule_arraychain.rb', line 23

def [](*a)
    if a.empty?
        raise TdlError.new("参数不能为空")
    end
    new_dla = self.class.new(@belong_to_module)
    new_dla.chain = @chain + a
    new_dla
end

#check_name(name) ⇒ Object



39
40
41
42
43
44
# File 'lib/tdl/sdlmodule/sdlmodule_arraychain.rb', line 39

def check_name(name)
    check_topmodule_method(name)
    if name.is_a? StringBandItegration
        raise TdlError.new("简化定义模式不允许传入 StringBandItegration 类型")
    end
end

#check_topmodule_method(name) ⇒ Object

简化模式定义时 打通topmodule 和 itgt 方法连接,需要topmodule没有定义同名方法



73
74
75
76
77
# File 'lib/tdl/sdlmodule/sdlmodule_arraychain.rb', line 73

def check_topmodule_method(name)
    if $_implicit_curr_itgt_.slast.respond_to?('top_module') && $_implicit_curr_itgt_.slast.top_module.respond_to?(name)
        raise TdlError.new("TopModule[#{$_implicit_curr_itgt_.slast.top_module.module_name}] 已经定义了方法 [#{name}],Itgt 不能定义新方法#{name},以免发生混淆")
    end
end

#to_inp(name) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/tdl/sdlmodule/sdlmodule_arraychain.rb', line 46

def to_inp(name)
    check_name(name)
    if $_implicit_curr_itgt_.slast
        yname = name.to_inp($_implicit_curr_itgt_.last)
    else 
        yname = name 
    end
    return yname 
end