ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:122242] [Ruby Feature#21365] Add `Namespace#eval`
@ 2025-05-22 23:28 tenderlovemaking (Aaron Patterson) via ruby-core
  2025-05-23 12:30 ` [ruby-core:122249] " matheusrich (Matheus Richard) via ruby-core
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: tenderlovemaking (Aaron Patterson) via ruby-core @ 2025-05-22 23:28 UTC (permalink / raw)
  To: ruby-core; +Cc: tenderlovemaking (Aaron Patterson)

Issue #21365 has been reported by tenderlovemaking (Aaron Patterson).

----------------------------------------
Feature #21365: Add `Namespace#eval`
https://bugs.ruby-lang.org/issues/21365

* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
----------------------------------------
I would like a way to eval code on to a `Namespace` object. Could we add an eval method that _doesn't_ take a binding object?  Writing a new file every time I want to test Namespaces is too cumbersome.

Thanks!



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:122249] [Ruby Feature#21365] Add `Namespace#eval`
  2025-05-22 23:28 [ruby-core:122242] [Ruby Feature#21365] Add `Namespace#eval` tenderlovemaking (Aaron Patterson) via ruby-core
@ 2025-05-23 12:30 ` matheusrich (Matheus Richard) via ruby-core
  2025-05-23 13:58 ` [ruby-core:122250] " Eregon (Benoit Daloze) via ruby-core
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: matheusrich (Matheus Richard) via ruby-core @ 2025-05-23 12:30 UTC (permalink / raw)
  To: ruby-core; +Cc: matheusrich (Matheus Richard)

Issue #21365 has been updated by matheusrich (Matheus Richard).


I'm curious why `eval` and not `instance_eval`?

----------------------------------------
Feature #21365: Add `Namespace#eval`
https://bugs.ruby-lang.org/issues/21365#change-113395

* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
----------------------------------------
I would like a way to eval code on to a `Namespace` object. Could we add an eval method that _doesn't_ take a binding object?  Writing a new file every time I want to test Namespaces is too cumbersome.

Thanks!



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:122250] [Ruby Feature#21365] Add `Namespace#eval`
  2025-05-22 23:28 [ruby-core:122242] [Ruby Feature#21365] Add `Namespace#eval` tenderlovemaking (Aaron Patterson) via ruby-core
  2025-05-23 12:30 ` [ruby-core:122249] " matheusrich (Matheus Richard) via ruby-core
@ 2025-05-23 13:58 ` Eregon (Benoit Daloze) via ruby-core
  2025-05-23 16:52 ` [ruby-core:122254] " matheusrich (Matheus Richard) via ruby-core
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2025-05-23 13:58 UTC (permalink / raw)
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

Issue #21365 has been updated by Eregon (Benoit Daloze).


Yep, agreed it'd be far more convenient for testing Namespace.

matheusrich (Matheus Richard) wrote in #note-1:
> I'm curious why `eval` and not `instance_eval`?

Why `instance_eval`? The distinction between eval/class_eval/instance_eval does not seem relevant here.

Though of course the semantics should be the same as writing the code to a file + `Namespace#require` so e.g. `ns.eval "def foo = 42"` defines method `foo` on ns' copy of Object methods.

----------------------------------------
Feature #21365: Add `Namespace#eval`
https://bugs.ruby-lang.org/issues/21365#change-113396

* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
----------------------------------------
I would like a way to eval code on to a `Namespace` object. Could we add an eval method that _doesn't_ take a binding object?  Writing a new file every time I want to test Namespaces is too cumbersome.

Thanks!



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:122254] [Ruby Feature#21365] Add `Namespace#eval`
  2025-05-22 23:28 [ruby-core:122242] [Ruby Feature#21365] Add `Namespace#eval` tenderlovemaking (Aaron Patterson) via ruby-core
  2025-05-23 12:30 ` [ruby-core:122249] " matheusrich (Matheus Richard) via ruby-core
  2025-05-23 13:58 ` [ruby-core:122250] " Eregon (Benoit Daloze) via ruby-core
@ 2025-05-23 16:52 ` matheusrich (Matheus Richard) via ruby-core
  2025-05-23 17:02 ` [ruby-core:122255] " ufuk (Ufuk Kayserilioglu) via ruby-core
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: matheusrich (Matheus Richard) via ruby-core @ 2025-05-23 16:52 UTC (permalink / raw)
  To: ruby-core; +Cc: matheusrich (Matheus Richard)

Issue #21365 has been updated by matheusrich (Matheus Richard).


@Eregon I feel like that's more consistent with the rest of the language. I can't remember if any object as a `eval` method. But evaluating some code in a particular instance context makes me think of `instance_eval`. 

----------------------------------------
Feature #21365: Add `Namespace#eval`
https://bugs.ruby-lang.org/issues/21365#change-113399

* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
----------------------------------------
I would like a way to eval code on to a `Namespace` object. Could we add an eval method that _doesn't_ take a binding object?  Writing a new file every time I want to test Namespaces is too cumbersome.

Thanks!



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:122255] [Ruby Feature#21365] Add `Namespace#eval`
  2025-05-22 23:28 [ruby-core:122242] [Ruby Feature#21365] Add `Namespace#eval` tenderlovemaking (Aaron Patterson) via ruby-core
                   ` (2 preceding siblings ...)
  2025-05-23 16:52 ` [ruby-core:122254] " matheusrich (Matheus Richard) via ruby-core
@ 2025-05-23 17:02 ` ufuk (Ufuk Kayserilioglu) via ruby-core
  2025-05-23 19:43 ` [ruby-core:122259] " matheusrich (Matheus Richard) via ruby-core
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: ufuk (Ufuk Kayserilioglu) via ruby-core @ 2025-05-23 17:02 UTC (permalink / raw)
  To: ruby-core; +Cc: ufuk (Ufuk Kayserilioglu)

Issue #21365 has been updated by ufuk (Ufuk Kayserilioglu).


matheusrich (Matheus Richard) wrote in #note-3:
> @Eregon I feel like that's more consistent with the rest of the language. I can't remember if any object as a `eval` method. But evaluating some code in a particular instance context makes me think of `instance_eval`.

I am not sure I understand. All objects have an `eval` method in the form of `Kernel#eval`: https://ruby-doc.org/3.4.1/Kernel.html#method-i-eval

----------------------------------------
Feature #21365: Add `Namespace#eval`
https://bugs.ruby-lang.org/issues/21365#change-113400

* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
----------------------------------------
I would like a way to eval code on to a `Namespace` object. Could we add an eval method that _doesn't_ take a binding object?  Writing a new file every time I want to test Namespaces is too cumbersome.

Thanks!



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:122259] [Ruby Feature#21365] Add `Namespace#eval`
  2025-05-22 23:28 [ruby-core:122242] [Ruby Feature#21365] Add `Namespace#eval` tenderlovemaking (Aaron Patterson) via ruby-core
                   ` (3 preceding siblings ...)
  2025-05-23 17:02 ` [ruby-core:122255] " ufuk (Ufuk Kayserilioglu) via ruby-core
@ 2025-05-23 19:43 ` matheusrich (Matheus Richard) via ruby-core
  2025-05-26 10:00 ` [ruby-core:122294] " Eregon (Benoit Daloze) via ruby-core
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: matheusrich (Matheus Richard) via ruby-core @ 2025-05-23 19:43 UTC (permalink / raw)
  To: ruby-core; +Cc: matheusrich (Matheus Richard)

Issue #21365 has been updated by matheusrich (Matheus Richard).


@ufuk fair point. Although it is a private method, so we're never doing `"foo".eval(bar)`.

----------------------------------------
Feature #21365: Add `Namespace#eval`
https://bugs.ruby-lang.org/issues/21365#change-113403

* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
----------------------------------------
I would like a way to eval code on to a `Namespace` object. Could we add an eval method that _doesn't_ take a binding object?  Writing a new file every time I want to test Namespaces is too cumbersome.

Thanks!



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:122294] [Ruby Feature#21365] Add `Namespace#eval`
  2025-05-22 23:28 [ruby-core:122242] [Ruby Feature#21365] Add `Namespace#eval` tenderlovemaking (Aaron Patterson) via ruby-core
                   ` (4 preceding siblings ...)
  2025-05-23 19:43 ` [ruby-core:122259] " matheusrich (Matheus Richard) via ruby-core
@ 2025-05-26 10:00 ` Eregon (Benoit Daloze) via ruby-core
  2025-05-26 14:45 ` [ruby-core:122297] " fxn (Xavier Noria) via ruby-core
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2025-05-26 10:00 UTC (permalink / raw)
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

Issue #21365 has been updated by Eregon (Benoit Daloze).


`ns.eval "self"` would be the Namespace "main" object, not the `Namespace` instance itself, so `instance_eval` would be a bad fit here.

AFAIK, `instance_eval` is only called as such because any `def foo; end` inside it will definite a singleton method on the instance.
And similarly `class_eval` defines `def foo; end` as a class instance method.
This is not relevant here, `def foo; end` would have normal top-level `def` semantics (in that namespace).

----------------------------------------
Feature #21365: Add `Namespace#eval`
https://bugs.ruby-lang.org/issues/21365#change-113438

* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
----------------------------------------
I would like a way to eval code on to a `Namespace` object. Could we add an eval method that _doesn't_ take a binding object?  Writing a new file every time I want to test Namespaces is too cumbersome.

Thanks!



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:122297] [Ruby Feature#21365] Add `Namespace#eval`
  2025-05-22 23:28 [ruby-core:122242] [Ruby Feature#21365] Add `Namespace#eval` tenderlovemaking (Aaron Patterson) via ruby-core
                   ` (5 preceding siblings ...)
  2025-05-26 10:00 ` [ruby-core:122294] " Eregon (Benoit Daloze) via ruby-core
@ 2025-05-26 14:45 ` fxn (Xavier Noria) via ruby-core
  2025-05-26 15:05 ` [ruby-core:122298] " matheusrich (Matheus Richard) via ruby-core
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: fxn (Xavier Noria) via ruby-core @ 2025-05-26 14:45 UTC (permalink / raw)
  To: ruby-core; +Cc: fxn (Xavier Noria)

Issue #21365 has been updated by fxn (Xavier Noria).


`instance_eval` modifies the nesting in the eval'ed code. Since namespaces are modules, `instance_eval` already works:

```ruby
ns = Namespace.new
ns.instance_eval "p Module.nesting"
```

That prints `[Namespace]`.

I believe @tenderlove's wants a regular top-level execution context, where the nesting would be empty, in particular (mod https://bugs.ruby-lang.org/issues/21318).

----------------------------------------
Feature #21365: Add `Namespace#eval`
https://bugs.ruby-lang.org/issues/21365#change-113441

* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
----------------------------------------
I would like a way to eval code on to a `Namespace` object. Could we add an eval method that _doesn't_ take a binding object?  Writing a new file every time I want to test Namespaces is too cumbersome.

Thanks!



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:122298] [Ruby Feature#21365] Add `Namespace#eval`
  2025-05-22 23:28 [ruby-core:122242] [Ruby Feature#21365] Add `Namespace#eval` tenderlovemaking (Aaron Patterson) via ruby-core
                   ` (6 preceding siblings ...)
  2025-05-26 14:45 ` [ruby-core:122297] " fxn (Xavier Noria) via ruby-core
@ 2025-05-26 15:05 ` matheusrich (Matheus Richard) via ruby-core
  2025-05-27  8:23 ` [ruby-core:122308] " fxn (Xavier Noria) via ruby-core
  2025-06-05  4:34 ` [ruby-core:122421] " matz (Yukihiro Matsumoto) via ruby-core
  9 siblings, 0 replies; 11+ messages in thread
From: matheusrich (Matheus Richard) via ruby-core @ 2025-05-26 15:05 UTC (permalink / raw)
  To: ruby-core; +Cc: matheusrich (Matheus Richard)

Issue #21365 has been updated by matheusrich (Matheus Richard).


Thanks for the clarification, everyone!

----------------------------------------
Feature #21365: Add `Namespace#eval`
https://bugs.ruby-lang.org/issues/21365#change-113442

* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
----------------------------------------
I would like a way to eval code on to a `Namespace` object. Could we add an eval method that _doesn't_ take a binding object?  Writing a new file every time I want to test Namespaces is too cumbersome.

Thanks!



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:122308] [Ruby Feature#21365] Add `Namespace#eval`
  2025-05-22 23:28 [ruby-core:122242] [Ruby Feature#21365] Add `Namespace#eval` tenderlovemaking (Aaron Patterson) via ruby-core
                   ` (7 preceding siblings ...)
  2025-05-26 15:05 ` [ruby-core:122298] " matheusrich (Matheus Richard) via ruby-core
@ 2025-05-27  8:23 ` fxn (Xavier Noria) via ruby-core
  2025-06-05  4:34 ` [ruby-core:122421] " matz (Yukihiro Matsumoto) via ruby-core
  9 siblings, 0 replies; 11+ messages in thread
From: fxn (Xavier Noria) via ruby-core @ 2025-05-27  8:23 UTC (permalink / raw)
  To: ruby-core; +Cc: fxn (Xavier Noria)

Issue #21365 has been updated by fxn (Xavier Noria).


I want to clarify that I explained that `instance_eval` works, and what it does, because `Namespace` is a `Module`.

But that does not mean I believe that is good.

Namespaces try to be one thing, but by being modules they carry other things that, in my view, are not quite coherent with the feature.

It is another instance of my hunch that namespaces should be a new entity with new rules.

In this particular case, I believe they should not respond to `instance_eval`, or `module_eval` or anything. Precisely, the proposed `eval` in this ticket is what makes sense to me: "run this code in your execution context".

----------------------------------------
Feature #21365: Add `Namespace#eval`
https://bugs.ruby-lang.org/issues/21365#change-113450

* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
----------------------------------------
I would like a way to eval code on to a `Namespace` object. Could we add an eval method that _doesn't_ take a binding object?  Writing a new file every time I want to test Namespaces is too cumbersome.

Thanks!



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:122421] [Ruby Feature#21365] Add `Namespace#eval`
  2025-05-22 23:28 [ruby-core:122242] [Ruby Feature#21365] Add `Namespace#eval` tenderlovemaking (Aaron Patterson) via ruby-core
                   ` (8 preceding siblings ...)
  2025-05-27  8:23 ` [ruby-core:122308] " fxn (Xavier Noria) via ruby-core
@ 2025-06-05  4:34 ` matz (Yukihiro Matsumoto) via ruby-core
  9 siblings, 0 replies; 11+ messages in thread
From: matz (Yukihiro Matsumoto) via ruby-core @ 2025-06-05  4:34 UTC (permalink / raw)
  To: ruby-core; +Cc: matz (Yukihiro Matsumoto)

Issue #21365 has been updated by matz (Yukihiro Matsumoto).


Namespace.eval accepted.

Matz.


----------------------------------------
Feature #21365: Add `Namespace#eval`
https://bugs.ruby-lang.org/issues/21365#change-113601

* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
----------------------------------------
I would like a way to eval code on to a `Namespace` object. Could we add an eval method that _doesn't_ take a binding object?  Writing a new file every time I want to test Namespaces is too cumbersome.

Thanks!



-- 
https://bugs.ruby-lang.org/
______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-06-05  4:34 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-22 23:28 [ruby-core:122242] [Ruby Feature#21365] Add `Namespace#eval` tenderlovemaking (Aaron Patterson) via ruby-core
2025-05-23 12:30 ` [ruby-core:122249] " matheusrich (Matheus Richard) via ruby-core
2025-05-23 13:58 ` [ruby-core:122250] " Eregon (Benoit Daloze) via ruby-core
2025-05-23 16:52 ` [ruby-core:122254] " matheusrich (Matheus Richard) via ruby-core
2025-05-23 17:02 ` [ruby-core:122255] " ufuk (Ufuk Kayserilioglu) via ruby-core
2025-05-23 19:43 ` [ruby-core:122259] " matheusrich (Matheus Richard) via ruby-core
2025-05-26 10:00 ` [ruby-core:122294] " Eregon (Benoit Daloze) via ruby-core
2025-05-26 14:45 ` [ruby-core:122297] " fxn (Xavier Noria) via ruby-core
2025-05-26 15:05 ` [ruby-core:122298] " matheusrich (Matheus Richard) via ruby-core
2025-05-27  8:23 ` [ruby-core:122308] " fxn (Xavier Noria) via ruby-core
2025-06-05  4:34 ` [ruby-core:122421] " matz (Yukihiro Matsumoto) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).