-
Notifications
You must be signed in to change notification settings - Fork 15
Allow use of DelegateClass in ractors without Ractor.shareable_proc #53
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
Conversation
|
Please fix the conflict. |
414722d to
aa8161a
Compare
hsbt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I'm trying to test with ruby/ruby after merging.
lib/delegate.rb
Outdated
| end | ||
| protected_instance_methods.each do |method| | ||
| define_method(method, Delegator.delegating_block(method)) | ||
| module_eval(*Delegator.delegating_code(method)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small optimization: We could do the protected call inside the delegating_code too now. If we send an extra parameter named visibility to delegating_code method, then it can do ruby2_keywords #{visibility} def #{mid}(*args, &block) instead.
22524d8 to
336a841
Compare
Use `eval` instead of `define_method` when defining delegate methods for `DelegateClass`.
336a841 to
ab3dcaa
Compare
| def Delegator.delegating_code(mid) # :nodoc: | ||
| line = __LINE__+2 | ||
| src = <<~RUBY | ||
| ruby2_keywords def #{mid}(*args, &block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mid can be any String by defining define_method, so it is not safe to use it directly here.
For example, checking /[A-z_][A-z\d_]+/ is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class C
define_method("_; end; 1.tap do ;"){}
end
p C.instance_methods.grep(/;/) #=> [:"_; end; 1.tap do ;"]|
I merged this at 6e0f2b3 manually. After I'm thinking #53 (comment). It seems that @byroot implementation (#51) can be used with Ractor in simple cases. I confirmed that #54. We should restore the |
We could also extend the eval <<~RUBY
def _temp_af53bef
source
end
alias_method :"€¢", :_temp_af53bef
undef_method :_temp_af53bef
RUBY |
Tempfile uses DelegateClass and Tempfile should be able to be used inside Ractors.