aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-110/abigail/README.md1
-rw-r--r--challenge-110/abigail/ruby/ch-2.rb30
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-110/abigail/README.md b/challenge-110/abigail/README.md
index 679024e8bb..e70d4d7b4e 100644
--- a/challenge-110/abigail/README.md
+++ b/challenge-110/abigail/README.md
@@ -82,6 +82,7 @@ sex,m,m,f,f
* [Lua](lua/ch-2.lua)
* [Node.js](node/ch-2.js)
* [Perl](perl/ch-2.pl)
+* [Ruby](ruby/ch-2.rb)
### Blog
diff --git a/challenge-110/abigail/ruby/ch-2.rb b/challenge-110/abigail/ruby/ch-2.rb
new file mode 100644
index 0000000000..9177342a45
--- /dev/null
+++ b/challenge-110/abigail/ruby/ch-2.rb
@@ -0,0 +1,30 @@
+#!/usr/bin/ruby
+
+#
+# See ../README.md
+#
+
+#
+# Run as: ruby ch-2.rb < input-file
+#
+
+output = []
+
+#
+# Read the input, split on comma, build output strings.
+#
+ARGF . each_line do
+ |_|
+ _ . strip . split(/,/) . each_with_index do
+ |_, i|
+ output [i] = (output [i] || "") + _ + ","
+ end
+end
+
+#
+# Print the output strings, without the trailing commas.
+#
+output . each do
+ |_|
+ puts _ [0 .. -2]
+end