rubyx/lib/ruby/return_statement.rb
Torsten Rüger 32f908c127 Adding simple implicit return
Ruby return semantics are easy to grasp, not so easy to code. So many cases.
Added support for common cases, return const/variable or call.
2019-08-17 23:27:55 +03:00

23 lines
479 B
Ruby

module Ruby
class ReturnStatement < Statement
include Normalizer
attr_reader :return_value
def initialize(value)
@return_value = value || NilConstant.new
end
def to_vool
val , hoisted = *normalized_vool(@return_value)
me = Vool::ReturnStatement.new(val)
return me unless hoisted
Vool::Statements.new( hoisted ) << me
end
def to_s(depth = 0)
at_depth(depth , "return #{@return_value.to_s}")
end
end
end