From fea4d1d76ce302c08823c4eb72f99cfdd865a08b Mon Sep 17 00:00:00 2001 From: Jaroslaw Zabiello Date: Tue, 8 Feb 2022 02:20:47 +0000 Subject: [PATCH] add improved Ruby version --- README.md | 2 +- example-ruby/README.md | 12 +++++++++++- example-ruby/words.rb | 18 ++---------------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index dc9f9cf..f6d4e8f 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ The new optimized Golang code version is very fast, slower than Rust but faster * Python = has a great implementation of [ICU](https://icu.unicode.org/related) library however it does not support arm64/M1 platform, hence I couldn't use it in this comparison. -* Ruby = can sort unicode text but withot collations becase it can't use ICU on arm64/M1 +* Ruby = can sort unicode text but without collations becase it can't use ICU on arm64/M1 * Elixir = same as Python, no ICU for M1. diff --git a/example-ruby/README.md b/example-ruby/README.md index aada47e..726e0e5 100644 --- a/example-ruby/README.md +++ b/example-ruby/README.md @@ -2,7 +2,17 @@ ## setup and run +Syntax + ``` -ruby words.rb +❯ ruby words.rb -h +Usage: ruby words.rb [options] + -n [NUM] Number of cores to run (default 10) + -s Sort results ``` +Run + +``` +ruby word.rb -s +``` diff --git a/example-ruby/words.rb b/example-ruby/words.rb index 95686ba..ccc1bad 100644 --- a/example-ruby/words.rb +++ b/example-ruby/words.rb @@ -4,7 +4,7 @@ require 'fileutils' require 'optparse' -class WordExtractor +class WordsExtractor def initialize(cores: Etc.nprocessors, sorting: false, outdir: 'words', source: '../data/??/**/*.yml') @cores = cores @sorting = sorting @@ -64,19 +64,5 @@ def run end opts.on('-s', 'Sort results') { |v| options[:s] = v } end.parse! - WordExtractor.new(cores: options[:n], sorting: options[:s]).run + WordsExtractor.new(cores: options[:n], sorting: options[:s]).run end - -# class A -# def initialize(x:, y:, z:) -# @x = x -# @y = y -# @z = z -# end - -# def run -# puts "x=#{@x}, y=#{@y}, z=#{@z}" -# end -# end - -# A.new(y: 'Y', x: 'X', z: 'Z').run