Module: Module::ModuleExtensions

Included in:
Module
Defined in:
lib/libmatty/module.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



62
63
64
# File 'lib/libmatty/module.rb', line 62

def self.included(klass)
  klass.extend ClassMethods
end

Instance Method Details

#class_def(name, &blk) ⇒ Object

Dynamically create instance methods



47
48
49
# File 'lib/libmatty/module.rb', line 47

def class_def(name, &blk)
    class_eval { define_method name, &blk }
end

#flag_dump(i) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/libmatty/module.rb', line 11

def flag_dump(i)
    @bit_map ||= constants.map do |k|
        [k, const_get(k.intern).ffs]
    end.sort {|x, y| x[1] <=> y[1]}

    last = 0
    r = ""
    @bit_map.each do |tup|
        if((v = (tup[1] - last)) > 1)
            r << ("." * (v-1))
        end

        if((i & (1 << tup[1])) != 0)
            r << tup[0][0].chr
        else
            r << tup[0][0].chr.downcase
        end
        last = tup[1]
    end
    return r.reverse
end

#stub(*args) ⇒ Object

When the base class method just returns nil



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/libmatty/module.rb', line 34

def stub(*args)
    opts = {}
    if args[-1].kind_of? Hash
        opts = args[-1]
        args = args[0..-2]
    end

    args.each do |meth|
        class_def(meth) do |*a|; nil; end
    end
end

#to_key_hashObject



7
8
9
# File 'lib/libmatty/module.rb', line 7

def to_key_hash
    @key_hash ||= constants.map {|k| [const_get(k.intern), k.intern]}.to_hash
end

#to_name_hashObject



3
4
5
# File 'lib/libmatty/module.rb', line 3

def to_name_hash
    @name_hash ||= constants.map {|k| [k.intern, const_get(k.intern)]}.to_hash
end