aboutsummaryrefslogtreecommitdiff
path: root/challenge-112/abigail/ruby/ch-1.rb
diff options
context:
space:
mode:
authordms061 <dms7225@psu.edu>2021-05-16 18:47:40 -0400
committerdms061 <dms7225@psu.edu>2021-05-16 18:47:40 -0400
commit0602d0d635835efc141bf1a89f604cd3156ecd3e (patch)
treea3cf4fbbe6f6378b1e7f0180ab722010493d6c7d /challenge-112/abigail/ruby/ch-1.rb
parent111673b82066733c69a62c8f1030da605767aaf8 (diff)
parentfa969a62c402d6220e260e0f302c80e9b6133c90 (diff)
downloadperlweeklychallenge-club-0602d0d635835efc141bf1a89f604cd3156ecd3e.tar.gz
perlweeklychallenge-club-0602d0d635835efc141bf1a89f604cd3156ecd3e.tar.bz2
perlweeklychallenge-club-0602d0d635835efc141bf1a89f604cd3156ecd3e.zip
Merge branch 'manwar:master' into challenge112
Diffstat (limited to 'challenge-112/abigail/ruby/ch-1.rb')
-rw-r--r--challenge-112/abigail/ruby/ch-1.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-112/abigail/ruby/ch-1.rb b/challenge-112/abigail/ruby/ch-1.rb
new file mode 100644
index 0000000000..e26463cb68
--- /dev/null
+++ b/challenge-112/abigail/ruby/ch-1.rb
@@ -0,0 +1,27 @@
+#!/usr/bin/ruby
+
+#
+# See ../README.md
+#
+
+#
+# Run as: ruby ch-1.rb < input-file
+#
+
+ARGF . each_line do
+ | line |
+ parts = line . strip() . split (/\/+/)
+ parts2 = []
+ parts . each do
+ | part |
+ if part == "" or part == "." # Skip empty parts and current directory
+ next
+ end
+ if part == ".." # Remove parent directory
+ parts2 . pop
+ next
+ end
+ parts2 . push (part) # Add part
+ end
+ puts ("/" + parts2 . join("/")) # Print result
+end