Kernel#Symbol
Returns a Symbol
based on the given argument.
Status
Installation
Add this line to your application's Gemfile:
gem "kernel-symbol"
And then execute:
bundle install
Or install it yourself as:
gem install kernel-symbol
Usage
If the argument is a symbol, returns the symbol. If the argument is not a symbol, tries to convert to a symbol.
In all other cases, returns an error.
Example
require "kernel/symbol"
Symbol(:foo) # => :foo
Symbol("foo") # => :foo
Symbol(true) # => :true
Symbol(42) # => :"42"
Symbol(BasicObject.new) # TypeError (can't convert BasicObject into String)
Note
The #Symbol
method could be used similarly to the methods already present in the Kernel
module:
#Array
#Complex
#Float
#Hash
#Integer
#Rational
#String
Warning
The Kernel
module is included in the Object
class, so by loading this library, the #Symbol
method will be available in every Ruby object.
Versioning
Kernel#Symbol
uses Semantic Versioning 2.0.0
See also
-
kernel-boolean
: Returns aBoolean
based on the given argument.
License
The gem is available as open source under the terms of the MIT License.