Toot

Written by Simon George on 2024-05-17 at 15:07

Ruby challenge! Can anyone find a way to get the names of the local variables defined within an arbitrary lambda without changing the lambda? Example lambda:

prk = ->{a=1, b=2}
[#] …
some_magic(prk) #=> [:a, :b]

My first thought was prk.binding.local_variables but Proc#binding returns the binding of the caller not the inner binding. And it's an arbitrary lambda so no variable shadowing ;-)

It's for a silly personal project not prod so I'm happy with weird metaprogramming!

=> More informations about this toot | View the thread | More toots from sfcgeorge@ruby.social

Mentions

Tags

Proxy Information
Original URL
gemini://mastogem.picasoft.net/toot/112457051328966052
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
219.275035 milliseconds
Gemini-to-HTML Time
0.329246 milliseconds

This content has been proxied by September (ba2dc).