module R::Tool

Utility functions aimed at library writers.

Public Class Methods

load_dir(d) click to toggle source

load every script in the directory d.

# File lib/rub/r/tool.rb, line 146
def self.load_dir(d)
        d = C.path(d)
        
        d.children.each {|i| load i}
end
make_array(a) click to toggle source

Make argument an array.

Turns a single item into an array or copies an array.

R::Tool.make_array  :item  #=> [:item]
R::Tool.make_array [:item] #=> [:item]

a = ["string1", "string2"]
b = R::Tool.make_array a   #=> ["string1", "string2"]
a.equal? b                 #=> false
a[0].equal? b[0]           #=> true
a[1].equal? b[1]           #=> true
# File lib/rub/r/tool.rb, line 108
def self.make_array(a)
        if a.respond_to? :to_a
                a.to_a.dup
        else
                [a]
        end
end
make_array_paths(a) click to toggle source

Make argument an array of Pathname objects.

@see make_array

a = C.path('root.rub')          #=> #<Pathname:root.rub>
b = 'dir.rub'                   #=> "dir.rub"
R::Tool.make_array_paths a      #=> [#<Pathname:/path/to/root.rub>]
R::Tool.make_array_paths [a]    #=> [#<Pathname:/path/to/root.rub>]
R::Tool.make_array_paths [a, b] #=> [#<Pathname:/path/to/root.rub>, #<Pathname:/path/to/dir.rub>]
R::Tool.make_array_paths b      #=> [#<Pathname:/path/to/dir.rub>]
# File lib/rub/r/tool.rb, line 132
def self.make_array_paths(a)
        make_array(a).map do |p|
                C.path(p)
        end
end
make_set(a) click to toggle source

Make argument a set.

@see make_array

# File lib/rub/r/tool.rb, line 118
def self.make_set(a)
        make_array(a).to_set
end
make_set_paths(a) click to toggle source

Make argument a Set of Pathname objects.

@see make_array_paths

# File lib/rub/r/tool.rb, line 141
def self.make_set_paths(a)
        make_array_paths(a).to_set
end