Skip to content
Related Articles

Related Articles

Ruby | Symbol slice function
  • Last Updated : 10 Dec, 2019

Symbol#slice() : slice() is a Symbol class method which slices the symbol object and return the character value.

Syntax: Symbol.slice()

Parameter: Symbol values

Return: slices the symbol object and return the character value.

Example #1 :






# Ruby code for Symbol.slice() 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"
  
  
# slice form 
puts "Symbol a slice form : #{a.slice(1)}\n\n"
puts "Symbol b slice form : #{b.slice(1)}\n\n"
puts "Symbol c slice form : #{c.slice(3)}\n\n"


Output :

Symbol a : aBcDeF

Symbol b : äöü

Symbol c : ABCDEF



Symbol a slice form : B

Symbol b slice form : ö

Symbol c slice form : D

Example #2 :




# Ruby code for Symbol.slice() 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"
  
  
# slice form 
puts "Symbol a slice form : #{a.slice(1)}\n\n"
puts "Symbol b slice form : #{b.slice(1)}\n\n"
puts "Symbol c slice form : #{c.slice(3)}\n\n"


Output :

Symbol a : geeks

Symbol b : åöó

Symbol c : GEEKS



Symbol a slice form : e

Symbol b slice form : ö

Symbol c slice form : K

My Personal Notes arrow_drop_up
Recommended Articles
Page :