Ruby | abbrev function
Last Updated :
25 Oct, 2019
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:
require 'abbrev'
A = %w{ Geek }.abbrev
B = %w{ gfg }.abbrev
puts "#{A}"
puts "#{B}"
|
Output:
{"Geek"=>"Geek", "Gee"=>"Geek", "Ge"=>"Geek", "G"=>"Geek"}
{"gfg"=>"gfg", "gf"=>"gfg", "g"=>"gfg"}
Example 2:
require 'abbrev'
A = %w{ Geek CSE }.abbrev
B = %w{ gfg GFG }.abbrev
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"}
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...