Class: DeadCodeTerminator::Cond::EnvIndex
- Inherits:
-
Base
- Object
- Base
- DeadCodeTerminator::Cond::EnvIndex
show all
- Defined in:
- lib/dead_code_terminator/cond/env_index.rb
Overview
ENV
s(:send,
s(:const, nil, :ENV), :[],
s(:str, "FLAG"))
Constant Summary
Constants inherited
from Base
Base::ELSE, Base::THEN
Instance Attribute Summary
Attributes inherited from Base
#ast, #env
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#given_env_key(ast) ⇒ Object
28
29
30
|
# File 'lib/dead_code_terminator/cond/env_index.rb', line 28
def given_env_key(ast)
env.keys.detect { |key| ast == s(:str, key) }
end
|
#value ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/dead_code_terminator/cond/env_index.rb', line 11
def value
return if ast.type != :send
hash, bracket_meth, *args = ast.children
return if hash != s(:const, nil, :ENV)
return if bracket_meth != :[]
return if args.size != 1
key = args[0]
return unless (matched_env_key = given_env_key(key))
env[matched_env_key] ? THEN : ELSE
end
|