Ruby 符号 intern函数
Symbol#intern() : intern() 是Symbol类的一个方法,用于返回符号所对应的对象。
语法。符号.intern()
参数。符号值
返回:符号所对应的对象
例子 #1 :
# Ruby code for Symbol.intern() method
# declaring Symbol
a = :aBcDeF
# declaring Symbol
b = :"\u{e4 f6 fc}"
# declaring Symbol
c = :ABCDEF
# intern form
puts "Symbol a intern form : #{a.intern}\n\n"
puts "Symbol b intern form : #{b.intern}\n\n"
puts "Symbol c intern form : #{c.intern}\n\n"
输出:
Symbol a intern form : aBcDeF
Symbol b intern form : äöü
Symbol c intern form : ABCDEF
例子 #2 :
# Ruby code for Symbol.intern() method
# declaring Symbol
a = :geeks
# declaring Symbol
b = :"\u{e5 f6 f3}"
# declaring Symbol
c = :GEEKS
# intern form
puts "Symbol a intern form : #{a.intern}\n\n"
puts "Symbol b intern form : #{b.intern}\n\n"
puts "Symbol c intern form : #{c.intern}\n\n"
输出:
Symbol a intern form : geeks
Symbol b intern form : åöó
Symbol c intern form : GEEKS