Module: R::Tool
- Defined in:
- lib/rub/r/tool.rb
Overview
Utility functions aimed at library writers.
Defined Under Namespace
Classes: PathArray
Class Method Summary collapse
-
.load_dir(d) ⇒ Object
load every script in the directory
d
. -
.make_array(a) ⇒ Object
Make argument an array.
-
.make_array_paths(a) ⇒ Object
Make argument an array of Pathname objects.
-
.make_set(a) ⇒ Object
Make argument a set.
-
.make_set_paths(a) ⇒ Object
Make argument a Set of Pathname objects.
Class Method Details
.load_dir(d) ⇒ Object
load every script in the directory d
.
146 147 148 149 150 |
# 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) ⇒ Object
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
108 109 110 111 112 113 114 |
# 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) ⇒ Object
Make argument an array of Pathname objects.
132 133 134 135 136 |
# 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) ⇒ Object
Make argument a set.
118 119 120 |
# File 'lib/rub/r/tool.rb', line 118 def self.make_set(a) make_array(a).to_set end |
.make_set_paths(a) ⇒ Object
Make argument a Set of Pathname objects.
141 142 143 |
# File 'lib/rub/r/tool.rb', line 141 def self.make_set_paths(a) make_array_paths(a).to_set end |