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 functionrequire 'abbrev' # Calling the abbrev function with stringA = %w{ Geek }.abbrevB = %w{ gfg }.abbrev # Getting the set of unambiguous # abbreviations for the string in self.puts "#{A}"puts "#{B}" |
Output:
{"Geek"=>"Geek", "Gee"=>"Geek", "Ge"=>"Geek", "G"=>"Geek"}
{"gfg"=>"gfg", "gf"=>"gfg", "g"=>"gfg"}Example 2:
# Ruby Program of abbrev functionrequire 'abbrev' # Calling the abbrev function with some stringsA = %w{ Geek CSE }.abbrevB = %w{ gfg GFG }.abbrev # Getting the set of unambiguous # abbreviations for the strings in self.puts "#{A}"puts "#{B}" |
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"}


