Ruby generator support for mass assignments
This commit is contained in:
parent
53c142ca26
commit
c98ba21a87
|
@ -41,6 +41,21 @@ module Oga
|
|||
"#{var_str} = #{val_str}"
|
||||
end
|
||||
|
||||
##
|
||||
# Processes a mass assignment node.
|
||||
#
|
||||
# @param [Oga::Ruby::Node] ast
|
||||
# @return [String]
|
||||
#
|
||||
def on_massign(ast)
|
||||
vars, val = *ast
|
||||
|
||||
var_names = vars.map { |var| process(var) }
|
||||
val_str = process(val)
|
||||
|
||||
"#{var_names.join(', ')} = #{val_str}"
|
||||
end
|
||||
|
||||
##
|
||||
# Processes an equality node.
|
||||
#
|
||||
|
|
|
@ -25,6 +25,18 @@ describe Oga::Ruby::Generator do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#on_mass_assign' do
|
||||
it 'returns a String' do
|
||||
var1 = Oga::Ruby::Node.new(:lit, %w{foo})
|
||||
var2 = Oga::Ruby::Node.new(:lit, %w{bar})
|
||||
val = Oga::Ruby::Node.new(:lit, %w{10})
|
||||
|
||||
assign = Oga::Ruby::Node.new(:massign, [[var1, var2], val])
|
||||
|
||||
@generator.on_massign(assign).should == 'foo, bar = 10'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#on_eq' do
|
||||
it 'returns a String' do
|
||||
var = Oga::Ruby::Node.new(:lit, %w{number})
|
||||
|
|
Loading…
Reference in New Issue