Module: Banalize::Parser::ShellVariables
- Included in:
- Banalize::Parser
- Defined in:
- lib/banalize/parser/variables.rb
Overview
Parse and detect all shell variables used in script. Set instance level accessor ‘variables`.
Instance Attribute Summary collapse
-
#variables ⇒ Object
All variables used in shell script.
Instance Method Summary collapse
-
#shell_variables ⇒ Array
Parse and detect all shell variables used in script.
Instance Attribute Details
#variables ⇒ Object
All variables used in shell script
26 27 28 |
# File 'lib/banalize/parser/variables.rb', line 26 def variables @variables end |
Instance Method Details
#shell_variables ⇒ Array
Parse and detect all shell variables used in script.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/banalize/parser/variables.rb', line 14 def shell_variables ln = code.grep(/\$\{?\w+\}?/).map(&:last).join " " vars = ln.scan(/\$\{?\w+\}?/) vars.map! { |x| x.gsub(/[${}]/,'') } vars.reject! { |x| x =~ /^\d$/} @variables = vars || [] @variables.uniq! end |