List local variables

Similar to @type.instance_vars I would like to get all local vars from a block/method, sample:

macro print_local_vars
  var1 = 10
  var2 = "Sample var"
  {% puts @type.local_variables %}
end
print_local_vars() # ==> should print { var1 => 10, var2 => "Sample var" }

This is currently impossible. It could probably be implemented, but I don’t see an immediate use case.
What do you want to do with that?

It seems is this: Re runs all previous commands generates unexpected results · Issue #127 · crystal-community/icr · GitHub

But there’s no need to have this in the language: Re runs all previous commands generates unexpected results · Issue #127 · crystal-community/icr · GitHub

1 Like

Hey @straight-shoota
My idea is to improve icr library to save all local variables from previous commands, more details in this comment (wanted to have a better REPL alternative very important for Ruby developers):

Thanks for answering my question.

1 Like