diff --git a/gems/abbrev/.rubocop.yml b/gems/abbrev/.rubocop.yml new file mode 100644 index 000000000..7d0be8ff2 --- /dev/null +++ b/gems/abbrev/.rubocop.yml @@ -0,0 +1,19 @@ +# This configuration inherits from /.rubocop.yml. +# You can configure RBS style of this gem. +# This file is used on CI. It is configured to automatically +# make rubocop suggestions on pull requests for this gem. +# If you do not like the style enforcement, you should remove this file. +inherit_from: ../../.rubocop.yml + +## +# If you want to customize the style, please consult with the gem reviewers. +# You can see the list of cops at https://github.com/ksss/rubocop-on-rbs/blob/main/docs/modules/ROOT/pages/cops.adoc + +RBS/Layout: + Enabled: true + +RBS/Lint: + Enabled: true + +RBS/Style: + Enabled: true diff --git a/gems/abbrev/0.1/_test/test.rb b/gems/abbrev/0.1/_test/test.rb new file mode 100644 index 000000000..8225211a8 --- /dev/null +++ b/gems/abbrev/0.1/_test/test.rb @@ -0,0 +1,10 @@ +# Write Ruby code to test the RBS. +# It is type checked by `steep check` command. + +require "abbrev" + +Abbrev.abbrev([]) +Abbrev.abbrev(%w(abbrev)) +Abbrev.abbrev(%w(abbrev), 'abb') +Abbrev.abbrev(%w(abbrev), /^abb/) +Abbrev.abbrev(%w(abbrev), nil) diff --git a/gems/abbrev/0.1/abbrev.rbs b/gems/abbrev/0.1/abbrev.rbs new file mode 100644 index 000000000..6370794c1 --- /dev/null +++ b/gems/abbrev/0.1/abbrev.rbs @@ -0,0 +1,66 @@ +# +# Calculates the set of unambiguous abbreviations for a given set of strings. +# +# require 'abbrev' +# require 'pp' +# +# pp Abbrev.abbrev(['ruby']) +# #=> {"ruby"=>"ruby", "rub"=>"ruby", "ru"=>"ruby", "r"=>"ruby"} +# +# pp Abbrev.abbrev(%w{ ruby rules }) +# +# *Generates:* +# { "ruby" => "ruby", +# "rub" => "ruby", +# "rules" => "rules", +# "rule" => "rules", +# "rul" => "rules" } +# +# It also provides an array core extension, Array#abbrev. +# +# pp %w{ summer winter }.abbrev +# +# *Generates:* +# { "summer" => "summer", +# "summe" => "summer", +# "summ" => "summer", +# "sum" => "summer", +# "su" => "summer", +# "s" => "summer", +# "winter" => "winter", +# "winte" => "winter", +# "wint" => "winter", +# "win" => "winter", +# "wi" => "winter", +# "w" => "winter" } +# +module Abbrev + # + # Given a set of strings, calculate the set of unambiguous abbreviations for + # those strings, and return a hash where the keys are all the possible + # abbreviations and the values are the full strings. + # + # Thus, given `words` is "car" and "cone", the keys pointing to "car" would be + # "ca" and "car", while those pointing to "cone" would be "co", "con", and + # "cone". + # + # require 'abbrev' + # + # Abbrev.abbrev(%w{ car cone }) + # #=> {"ca"=>"car", "con"=>"cone", "co"=>"cone", "car"=>"car", "cone"=>"cone"} + # + # The optional `pattern` parameter is a pattern or a string. Only input strings + # that match the pattern or start with the string are included in the output + # hash. + # + # Abbrev.abbrev(%w{car box cone crab}, /b/) + # #=> {"box"=>"box", "bo"=>"box", "b"=>"box", "crab" => "crab"} + # + # Abbrev.abbrev(%w{car box cone}, 'ca') + # #=> {"car"=>"car", "ca"=>"car"} + # + def self?.abbrev: (Array[String], ?String | Regexp | nil) -> Hash[String, String] +end diff --git a/gems/abbrev/0.1/array.rbs b/gems/abbrev/0.1/array.rbs new file mode 100644 index 000000000..5ea1f93ce --- /dev/null +++ b/gems/abbrev/0.1/array.rbs @@ -0,0 +1,26 @@ +%a{annotate:rdoc:skip} +class Array[unchecked out Elem] + # + # Calculates the set of unambiguous abbreviations for the strings in `self`. + # + # require 'abbrev' + # %w{ car cone }.abbrev + # #=> {"car"=>"car", "ca"=>"car", "cone"=>"cone", "con"=>"cone", "co"=>"cone"} + # + # The optional `pattern` parameter is a pattern or a string. Only input strings + # that match the pattern or start with the string are included in the output + # hash. + # + # %w{ fast boat day }.abbrev(/^.a/) + # #=> {"fast"=>"fast", "fas"=>"fast", "fa"=>"fast", "day"=>"day", "da"=>"day"} + # + # Abbrev.abbrev(%w{car box cone}, "ca") + # #=> {"car"=>"car", "ca"=>"car"} + # + # See also Abbrev.abbrev + # + def abbrev: (?String | Regexp | nil) -> Hash[String, String] +end diff --git a/gems/abbrev/_reviewers.yaml b/gems/abbrev/_reviewers.yaml new file mode 100644 index 000000000..0b4d3b7e8 --- /dev/null +++ b/gems/abbrev/_reviewers.yaml @@ -0,0 +1,2 @@ +reviewers: + - ksss