From 6b21ba5c2303a59a3cca7b693ea0a55faf766c95 Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 11 May 2021 01:24:43 +0200 Subject: Ruby solutions for week 112 --- challenge-112/abigail/ruby/ch-1.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 challenge-112/abigail/ruby/ch-1.rb (limited to 'challenge-112/abigail/ruby/ch-1.rb') 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 -- cgit