lib/ronin/path.rb in ronin-support-0.1.0.rc1 vs lib/ronin/path.rb in ronin-support-0.1.0.rc2

- old
+ new

@@ -68,11 +68,12 @@ # Path.up(1..3) # # => [#<Ronin::Path:..>, #<Ronin::Path:../..>, # #<Ronin::Path:../../..>] # def self.up(n,separator=File::SEPARATOR) - if n.kind_of?(Integer) + case n + when Integer if n == 0 return separator elsif n < 0 raise(ArgumentError,"negative argument") end @@ -81,11 +82,11 @@ path.separator = separator dirs = (['..'] * (n-1)) return Path.new(path.join(*dirs)) - elsif n.kind_of?(Enumerable) + when Enumerable return n.map { |i| self.up(i) } else raise(ArgumentError,"The first argument of Path.up must be either an Integer or Enumerable") end end @@ -103,16 +104,16 @@ # @example # Path.up(7).join('etc/passwd') # # => #<Ronin::Path:../../../../../../../etc/passwd> # def join(*names) - sub_dirs = names.map { |name| name.to_s } + names.map! { |name| name.to_s } # filter out errant directory separators - sub_dirs.reject! { |dir| dir == @separator } + names.reject! { |dir| dir == @separator } # join the path - sub_path = sub_dirs.join(@separator) + sub_path = names.join(@separator) path = if self.root? # prefix the root dir self.to_s + sub_path else