Open In App

Ruby | Symbol size function

Improve
Improve
Like Article
Like
Save
Share
Report

Symbol#size() : size() is a Symbol class method which returns the size/length of the symbol object.

Syntax: Symbol.size()

Parameter: Symbol values

Return: the size/length of the symbol object.

Example #1 :




# Ruby code for Symbol.size() method
  
# declaring Symbol 
a = :aBcDeF
  
# declaring Symbol
b = :"\u{e4 f6 fc}"
  
# declaring Symbol
c = :ABCDEF
  
# Symbol 
puts "Symbol a : #{a}\n\n"
puts "Symbol b : #{b}\n\n"
puts "Symbol c : #{c}\n\n\n\n"
  
  
# size form 
puts "Symbol a size form : #{a.size}\n\n"
puts "Symbol b size form : #{b.size}\n\n"
puts "Symbol c size form : #{c.size}\n\n"


Output :

Symbol a : aBcDeF

Symbol b : äöü

Symbol c : ABCDEF



Symbol a size form : 6

Symbol b size form : 3

Symbol c size form : 6

Example #2 :




# Ruby code for Symbol.size() method
  
# declaring Symbol 
a = :geeks
  
# declaring Symbol
b = :"\u{e5 f6 f3}"
  
# declaring Symbol
c = :GEEKS
  
# Symbol 
puts "Symbol a : #{a}\n\n"
puts "Symbol b : #{b}\n\n"
puts "Symbol c : #{c}\n\n\n\n"
  
  
# size form 
puts "Symbol a size form : #{a.size}\n\n"
puts "Symbol b size form : #{b.size}\n\n"
puts "Symbol c size form : #{c.size}\n\n"


Output :

Symbol a : geeks

Symbol b : åöó

Symbol c : GEEKS



Symbol a size form : 5

Symbol b size form : 3

Symbol c size form : 5



Last Updated : 10 Dec, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads