> For the complete documentation index, see [llms.txt](https://ploegert.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ploegert.gitbook.io/til/programmy/ruby/construct-a-constant-from-a-string.md).

# Construct A Constant From A String

Ruby's [`Module.const_get`](http://ruby-doc.org/core-2.1.0/Module.html#method-i-const_get) can be used to look for and retrieve the constant for a given name.

This can be used to construct a class name

```ruby
> Object.const_get("Math")
#=> Math
> Object.const_get("Math")::PI
#=> 3.141592653589793
```

It can also be used to reference a constant

```ruby
> Object.const_get("Math::PI")
#=> 3.141592653589793
```

You can even be more specific if you'd like

```ruby
> Math.const_get("PI")
#=> 3.141592653589793
```

Symbols are valid as well

```ruby
> Math.const_get(:PI)
#=> 3.141592653589793
```
