Skip to content

Conversation

@luke-gruber
Copy link
Contributor

Tempfile uses DelegateClass and Tempfile should be able to be used inside Ractors.

@hsbt
Copy link
Member

hsbt commented Dec 17, 2025

Please fix the conflict.

@luke-gruber luke-gruber force-pushed the delegate_class_ractors branch 2 times, most recently from 414722d to aa8161a Compare December 17, 2025 21:39
Copy link
Member

@hsbt hsbt left a 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))

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.

@hsbt hsbt force-pushed the delegate_class_ractors branch 2 times, most recently from 22524d8 to 336a841 Compare December 18, 2025 04:15
Use `eval` instead of `define_method` when defining delegate methods for
`DelegateClass`.
@hsbt hsbt force-pushed the delegate_class_ractors branch from 336a841 to ab3dcaa Compare December 18, 2025 04:19
def Delegator.delegating_code(mid) # :nodoc:
line = __LINE__+2
src = <<~RUBY
ruby2_keywords def #{mid}(*args, &block)
Copy link
Contributor

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.

Copy link
Contributor

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 ;"]

@hsbt
Copy link
Member

hsbt commented Dec 18, 2025

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 define_method for special cases.

@byroot
Copy link
Member

byroot commented Dec 18, 2025

We should restore the define_method for special cases.

We could also extend the eval implementation to non-simple methods, e.g.

eval <<~RUBY
  def _temp_af53bef
    source
  end
  alias_method :"€¢", :_temp_af53bef
  undef_method :_temp_af53bef
RUBY

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.

5 participants