Skip to content

Commit

Permalink
Update YARD documentation
Browse files Browse the repository at this point in the history
Specifically, use the @see tag instead of duplicating documentation
where possible. Also fix references to "RE2.new" instead of
"RE2::Regexp.new".
  • Loading branch information
mudge committed Oct 22, 2022
1 parent 8bb59cf commit 3913933
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 30 deletions.
16 changes: 4 additions & 12 deletions ext/re2/re2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -795,12 +795,9 @@ static VALUE re2_matchdata_deconstruct_keys(VALUE self, VALUE keys) {

/*
* Returns a new RE2 object with a compiled version of
* +pattern+ stored inside. Equivalent to +RE2.new+.
* +pattern+ stored inside. Equivalent to +RE2::Regexp.new+.
*
* @return [RE2::Regexp] an RE2::Regexp with the specified pattern and options
* @param [String] pattern the pattern to compile
* @param [Hash] options the options to compile a regexp with
* @see RE2::Regexp.new
* @see RE2::Regexp#initialize
*
*/
static VALUE re2_re2(int argc, VALUE *argv, VALUE self) {
Expand Down Expand Up @@ -1399,7 +1396,7 @@ static VALUE re2_regexp_scan(VALUE self, VALUE text) {
* @return [String] the resulting string
* @example
* RE2.Replace("hello there", "hello", "howdy") #=> "howdy there"
* re2 = RE2.new("hel+o")
* re2 = RE2::Regexp.new("hel+o")
* RE2.Replace("hello there", re2, "yo") #=> "yo there"
*/
static VALUE re2_Replace(VALUE self, VALUE str, VALUE pattern,
Expand Down Expand Up @@ -1435,7 +1432,7 @@ static VALUE re2_Replace(VALUE self, VALUE str, VALUE pattern,
* @param [String] rewrite the string to replace with
* @return [String] the resulting string
* @example
* re2 = RE2.new("oo?")
* re2 = RE2::Regexp.new("oo?")
* RE2.GlobalReplace("whoops-doops", re2, "e") #=> "wheps-deps"
* RE2.GlobalReplace("hello there", "e", "i") #=> "hillo thiri"
*/
Expand Down Expand Up @@ -1889,9 +1886,4 @@ void Init_re2(void) {
id_anchor_start = rb_intern("anchor_start");
id_anchor_both = rb_intern("anchor_both");
id_exception = rb_intern("exception");

#if 0
/* Fake so YARD generates the file. */
rb_mKernel = rb_define_module("Kernel");
#endif
}
20 changes: 2 additions & 18 deletions lib/re2/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,14 @@ module String
# Replaces the first occurrence +pattern+ with +rewrite+ and returns a new
# string.
#
# @param [String, RE2::Regexp] pattern a regexp matching text to be replaced
# @param [String] rewrite the string to replace with
# @example
# "hello there".re2_sub("hello", "howdy") #=> "howdy there"
# re2 = RE2.new("hel+o")
# "hello there".re2_sub(re2, "yo") #=> "yo there"
# text = "Good morning"
# text.re2_sub("morn", "even") #=> "Good evening"
# text #=> "Good morning"
# @see RE2.Replace
def re2_sub(*args)
RE2.Replace(self, *args)
end

# Replaces every occurrence of +pattern+ with +rewrite+ and return a new string.
#
# @param [String, RE2::Regexp] pattern a regexp matching text to be replaced
# @param [String] rewrite the string to replace with
# @example
# "hello there".re2_gsub("e", "i") #=> "hillo thiri"
# re2 = RE2.new("oo?")
# "whoops-doops".re2_gsub(re2, "e") #=> "wheps-deps"
# text = "Good morning"
# text.re2_gsub("o", "ee") #=> "Geeeed meerning"
# text #=> "Good morning"
# @see RE2.GlobalReplace
def re2_gsub(*args)
RE2.GlobalReplace(self, *args)
end
Expand Down

0 comments on commit 3913933

Please sign in to comment.