Ruby - Module Symbols Name

Description

Symbols Name

Demo

x = 1
xsymbol = :x# from www  .  j  av a2s . c  o  m

def amethod( somearg )
    p( somearg )
end

# Test 1
amethod( x )
amethod( :x )
amethod( eval(:x.id2name))

Result

Here, id2name is a method of the Symbol class.

It returns the name or string corresponding to the symbol.

The to_s method would perform the same function.

Ruby's eval method can evaluate talks within strings.

Related Topic