Top Level Namespace

Defined Under Namespace

Modules: ShnaiderCode

Instance Method Summary collapse

Instance Method Details

#attr_limited_regex_accessor(symbol, regex) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/source/attr_limited_regex_accessor.rb', line 1

def attr_limited_regex_accessor(symbol, regex)
    class_eval %{
        def #{symbol}
            @#{symbol}
        end

        def #{symbol}=(new_value)
            if new_value != nil && new_value !~ #{regex}
                raise "invalid #{symbol} format"
            end

            @#{symbol} = new_value
        end
    }
end

#attr_private_accessor(symbol) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/source/attr_limited_regex_accessor.rb', line 33

def attr_private_accessor(symbol)
    class_eval %{
        private def #{symbol}
            @#{symbol}
        end

        private def #{symbol}=(new_value)
            @#{symbol} = new_value
        end
    }
end

#attr_private_limited_regex_accessor(symbol, regex) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/source/attr_limited_regex_accessor.rb', line 17

def attr_private_limited_regex_accessor(symbol, regex)
    class_eval %{
        def #{symbol}
            @#{symbol}
        end

        private def #{symbol}=(new_value)
            if new_value != nil && new_value !~ #{regex}
                raise "invalid #{symbol} format"
            end

            @#{symbol} = new_value
        end
    }
end