Class: CodeTools::AST::Case
- Defined in:
- lib/rubinius/code/ast/control_flow.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#else ⇒ Object
Returns the value of attribute else.
-
#whens ⇒ Object
Returns the value of attribute whens.
Attributes inherited from Node
Instance Method Summary collapse
- #bytecode(g) ⇒ Object
- #defined(g) ⇒ Object
-
#initialize(line, whens, else_body) ⇒ Case
constructor
A new instance of Case.
- #receiver_sexp ⇒ Object
- #to_sexp ⇒ Object
Methods inherited from Node
#ascii_graph, #attributes, #children, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, #or_bytecode, #pos, #set_child, transform, #transform, transform_comment, transform_kind, transform_kind=, transform_name, #value_defined, #visit, #walk
Constructor Details
#initialize(line, whens, else_body) ⇒ Case
Returns a new instance of Case.
8 9 10 11 12 |
# File 'lib/rubinius/code/ast/control_flow.rb', line 8 def initialize(line, whens, else_body) @line = line @whens = whens @else = else_body || NilLiteral.new(line) end |
Instance Attribute Details
#else ⇒ Object
Returns the value of attribute else.
6 7 8 |
# File 'lib/rubinius/code/ast/control_flow.rb', line 6 def else @else end |
#whens ⇒ Object
Returns the value of attribute whens.
6 7 8 |
# File 'lib/rubinius/code/ast/control_flow.rb', line 6 def whens @whens end |
Instance Method Details
#bytecode(g) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rubinius/code/ast/control_flow.rb', line 14 def bytecode(g) pos(g) done = g.new_label @whens.each do |w| w.bytecode(g, done) end @else.bytecode(g) # See command in if about why using line 0 g.set_line 0 done.set! end |
#defined(g) ⇒ Object
31 32 33 |
# File 'lib/rubinius/code/ast/control_flow.rb', line 31 def defined(g) g.push_literal "expression" end |
#receiver_sexp ⇒ Object
35 36 37 |
# File 'lib/rubinius/code/ast/control_flow.rb', line 35 def receiver_sexp nil end |
#to_sexp ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/rubinius/code/ast/control_flow.rb', line 39 def to_sexp else_sexp = @else.kind_of?(NilLiteral) ? nil : @else.to_sexp sexp = [:case, receiver_sexp] sexp += @whens.map { |x| x.to_sexp } sexp << else_sexp sexp end |