Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Introduce Namespace#eval #13701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2025
Merged

Introduce Namespace#eval #13701

merged 1 commit into from
Jun 26, 2025

Conversation

tenderlove
Copy link
Member

@tenderlove tenderlove commented Jun 25, 2025

This commit adds an eval method to Namespace that takes a string and evaluates the string as Ruby code within the context of that namespace.

For example:

n = Namespace.new

n.eval("class TestClass; def hello; 'from namespace'; end; end")

instance = n::TestClass.new
instance.hello # => "from namespace"

[Feature #21365]

This commit adds an `eval` method to `Namespace` that takes a string and
evaluates the string as Ruby code within the context of that namespace.

For example:

```ruby
n = Namespace.new

n.eval("class TestClass; def hello; 'from namespace'; end; end")

instance = n::TestClass.new
instance.hello # => "from namespace"
```

[Feature #21365]
@tagomoris
Copy link
Contributor

LGTM 👍

@tenderlove tenderlove merged commit 3d5619c into ruby:master Jun 26, 2025
85 checks passed
@tenderlove tenderlove deleted the namespace-eval branch June 26, 2025 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants