Class: ToSource::Emitter::ReceiverCase

Inherits:
ToSource::Emitter show all
Defined in:
lib/to_source/emitter/receiver_case.rb

Constant Summary

Constants inherited from ToSource::Emitter

REGISTRY

Instance Attribute Summary

Attributes inherited from ToSource::Emitter

#node

Instance Method Summary collapse

Methods inherited from ToSource::Emitter

build, handle, run, #source

Instance Method Details

#dispatchObject



7
8
9
10
11
12
13
# File 'lib/to_source/emitter/receiver_case.rb', line 7

def dispatch
  emit('case ')
  visit(node.receiver)
  emit_whens
  emit_else
  emit_end
end

#emit_elseObject



15
16
17
18
19
20
21
22
# File 'lib/to_source/emitter/receiver_case.rb', line 15

def emit_else
  body = node.else
  return if body.kind_of?(Rubinius::AST::NilLiteral)
  emit('else')
  indent
  visit(body)
  unindent
end

#emit_whensObject



24
25
26
27
28
29
30
31
# File 'lib/to_source/emitter/receiver_case.rb', line 24

def emit_whens
  first = true
  node.whens.each do |member|
    new_line if first
    first = false
    visit(member)
  end
end