Search code examples
rubymetaprogramminglocal-variables

How to list local-variables in Ruby?


def method
  a = 3
  b = 4

  some_method_that_gives # [a, b] 
end

Solution

  • local_variables

    It outputs array of symbols, presenting variables. In your case: [:a, :b]