From: "Eregon (Benoit Daloze) via ruby-core" Date: 2024-05-25T02:40:47+00:00 Subject: [ruby-core:118013] [Ruby master Feature#20508] Explicit access to *, **, &, and ... Issue #20508 has been updated by Eregon (Benoit Daloze). > Implementing this would require removing recent and planned optimizations to avoid allocations that take advantage of the fact that `*` and `**` are not directly accessible as objects, only passable as splats. What if these methods would return a new Array/Hash/a copy of the real one? I'm not sure whether it's a good idea to add those methods but it does feel weird there is no easy way to display these variables in a debugger showing arguments by default. I suppose that eval trick is good enough though for that use case, although it seems a lot more expensive than Binding methods (a debugger would need the binding anyway and so already have it). Another issue with these methods is it does not seem clear if Binding#arguments would return all positional arguments or only the value of `*`. Same for kwargs. I suppose it's the latter, but that means the names are rather confusing then. ---------------------------------------- Feature #20508: Explicit access to *, **, &, and ... https://bugs.ruby-lang.org/issues/20508#change-108432 * Author: bradgessler (Brad Gessler) * Status: Open ---------------------------------------- I find debugging and certain meta-programming tasks challenging because there's no explicit APIs for accessing certain types of arguments in Ruby. Here's some example code: ```ruby def splats(one, *, two: nil, **, &) # These work p(*) p(**) # But the block doesn't show a proc. p(&) # This would show [:one, :two, :_] p binding.local_variables end splats(:arg, two: true) do 42 end ``` I'm not sure how to access the `&` variable, unless I name it. The same applies to endless ruby methods. I'd like to see a way to explicitly call bindings for those methods. Something like this (not sure if binding is the right place for it): ```ruby def splats(one, *, true: nil, **, &) binding.arguments # Returns an array binding.keyword_arguments # Returns a hash binding.block_argument # Returns a block end ``` These methods would give me access to the values used to call the method. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/