سؤال

def method
  a = 3
  b = 4

  some_method_that_gives # [a, b] 
end
هل كانت مفيدة؟

المحلول

local_variables

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

نصائح أخرى

local_variables lists local variables but it lists them before they are defined. See this:

p local_variables
a = 1
p local_variables

this outputs

[:a]
[:a]

which may not be what you expect. Contrast with defined?

p defined? a
a = 1
p defined? a

which outputs the more anticipated

nil
"local-variable"
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top