Skip to content

Conversation

nvh0412
Copy link

@nvh0412 nvh0412 commented Oct 7, 2025

Current approach: Always clones attrs and opts (in optional), then mutates and clones again
Optimized approach: remove redundant dup by writing our own extract_options! without mutating the input

Current approach: Always clones attrs and opts (in optional), then mutates and clones again
Optimized approach: remove redundant dup by writing our own extract_options! without mutating the input
@ericproulx
Copy link
Contributor

Current approach: Always clones attrs and opts (in optional), then mutates and clones again Optimized approach: remove redundant dup by writing our own extract_options! without mutating the input

Love the idea and I'm wondering if it would be possible to just add and extra parameter to the requires and optional methods.

Something like:

def requires(*attrs, **opts, &block)
 ...
end

If you open a console and add

def test(*attrs, **opts, &block)
  puts "attrs = #{attrs}"
  puts "opts = #{opts}"
end

and type

test :a, :b, c: :d

opts should be equal to c: :d

@nvh0412
Copy link
Author

nvh0412 commented Oct 7, 2025

I’ve thought about it, but the thing is we previously passed the original attributes (including the opts hash) into new_scope when there was a block. I haven't dug into new_scope yet, but by separating the hash and array parameters, we’d need to merge them back before passing them to new_scope to maintain backward compatibility.

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