# 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
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ploegert.gitbook.io/til/programmy/ruby/construct-a-constant-from-a-string.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
