Ruby | abbrev function
The abbrev function in Ruby is used to calculates the set of unambiguous abbreviations for the strings in self.
Syntax: %w{ Strings }.abbrev
Here String is the input word whose unambiguous abbreviations are going to be calculated.Parameters: This function does not accept any parameters.
Returns: the set of all possible unambiguous abbreviations.
Example 1:
# Ruby Program of abbrev function require 'abbrev' # Calling the abbrev funtion with string A = %w{ Geek }.abbrev B = %w{ gfg }.abbrev # Getting the set of unambiguous # abbreviations for the string in self. puts "#{A}"puts "#{B}" |
chevron_right
filter_none
Output:
{"Geek"=>"Geek", "Gee"=>"Geek", "Ge"=>"Geek", "G"=>"Geek"}
{"gfg"=>"gfg", "gf"=>"gfg", "g"=>"gfg"}
Example 2:
# Ruby Program of abbrev function require 'abbrev' # Calling the abbrev funtion with some strings A = %w{ Geek CSE }.abbrev B = %w{ gfg GFG }.abbrev # Getting the set of unambiguous # abbreviations for the strings in self. puts "#{A}"puts "#{B}" |
chevron_right
filter_none
Output:
{"Geek"=>"Geek", "Gee"=>"Geek", "Ge"=>"Geek", "G"=>"Geek", "CSE"=>"CSE", "CS"=>"CSE", "C"=>"CSE"}
{"gfg"=>"gfg", "gf"=>"gfg", "g"=>"gfg", "GFG"=>"GFG", "GF"=>"GFG", "G"=>"GFG"}
Recommended Posts:
- Ruby | Array abbrev() function
- Ruby | Set add? function
- Ruby | pop() function
- Ruby | at() function
- Ruby | Regexp ==() function
- Ruby | Matrix det() function
- Ruby | Vector eql?() function
- Ruby | Regexp new() function
- Ruby | Array pop() function
- Ruby | Regexp ===() function
- Ruby | Symbol == function
- Ruby | Symbol =~ function
- Ruby | Struct eql?() function
- Ruby | Regexp eql?() function
- Ruby | Vector zero() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



