[#101179] Spectre Mitigations — Amel <amel.smajic@...>
Hi there!
5 messages
2020/12/01
[#101694] Ruby 3.0.0 Released — "NARUSE, Yui" <naruse@...>
V2UgYXJlIHBsZWFzZWQgdG8gYW5ub3VuY2UgdGhlIHJlbGVhc2Ugb2YgUnVieSAzLjAuMC4gRnJv
4 messages
2020/12/25
[ruby-core:101296] [Ruby master Bug#17374] Refined methods aren't visible from a refinement's module
From:
merch-redmine@...
Date:
2020-12-07 21:44:58 UTC
List:
ruby-core #101296
Issue #17374 has been updated by jeremyevans0 (Jeremy Evans).
marcandre (Marc-Andre Lafortune) wrote in #note-7:
> jeremyevans0 (Jeremy Evans) wrote in #note-6:
> > This is because `refine` implicitly activates the refinement, so the refinement is active at the point `bar` is called. This approach works back to Ruby 2.0, with output:
> >
> > ```
> > :none
> > :none
> > 42
> > ```
>
> Thanks for trying it out.
> This is not the desired output, though. The last `using` has no effect. Desired output is:
> ```
> :none # No refinement active yet
> 42 # using was activated
> 42 # extend works too (assuming the `using` part is commented out...
> ```
Ah, thank you for clarifying. I still think the behavior is expected, even if my fix was bad, because the refinement is not active at the point of call. However, only @matz can decide whether this is a bug or expected behavior.
After playing around with it, I found a way to get it to work without duplicating the literal method definitions. It's not much better than calling `class_eval` with the same string in two places, though:
```ruby
class Foo
module Extension
RefinedImplementation = refine Foo do
def foo(value=:none)
super(bar) # << Can not see bar
end
def bar # << Bar is in the same module!
42
end
end
module Implementation
RefinedImplementation.public_instance_methods(false).each do |m|
define_method(m, RefinedImplementation.instance_method(m))
end
end
end
def foo(value = :none)
p value
end
end
```
I'd probably use `class_eval` with the same string instead of this.
----------------------------------------
Bug #17374: Refined methods aren't visible from a refinement's module
https://bugs.ruby-lang.org/issues/17374#change-88980
* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
* Assignee: shugo (Shugo Maeda)
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>