Skip to content

Conversation

@jhawthorn
Copy link
Member

@jhawthorn jhawthorn commented Dec 18, 2025

As @byroot suggested in #53 (comment)

This allows using the same code for both "specially named" and regular methods. This uses :__delegate as the placeholder method name, which may be visible to users in backtraces for these methods.

This allows using the same code for both "specially named" and regular
methods. This uses :__delegate as the name, which may be visible to
users in backtraces for these methods.

Co-authored-by: Luke Gruber <luke.gruber@shopify.com>
source << "def #{method}(...); __getobj__.__send__(#{method.inspect}, ...); end"
methods_to_define.each do |target_name, is_protected|
unless target_name.match?(/\A[a-zA-Z]\w*[!\?]?\z/)
placeholder_name = :__delegate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
placeholder_name = :__delegate
placeholder_name = "__delegate_#{target_name.unpack1("h*")}"

Active Model unpack the string in hexadecimal to get a unique name. May or may not be a good idea. Make sure there is no conflict and get unique name, but also define more symbols?

Up to you.

Copy link
Member Author

@jhawthorn jhawthorn Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to avoid creating extra symbols and since we're removing them I don't think there's a need for them to be unique.

It might be worth handling the case that we're delegating to something which has exactly __delegate defined...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
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