Ruby::Generator support for #[] methods
This commit is contained in:
parent
17f6b3a3bb
commit
cf2405998b
|
@ -126,15 +126,17 @@ end
|
||||||
def on_send(ast)
|
def on_send(ast)
|
||||||
receiver, name, *args = *ast
|
receiver, name, *args = *ast
|
||||||
|
|
||||||
call = name.dup
|
call = name
|
||||||
|
brackets = name == '[]'
|
||||||
|
|
||||||
unless args.empty?
|
unless args.empty?
|
||||||
arg_strs = args.map { |arg| process(arg) }
|
arg_str = args.map { |arg| process(arg) }.join(', ')
|
||||||
call = "#{call}(#{arg_strs.join(', ')})"
|
call = brackets ? "[#{arg_str}]" : "#{call}(#{arg_str})"
|
||||||
end
|
end
|
||||||
|
|
||||||
if receiver
|
if receiver
|
||||||
call = "#{process(receiver)}.#{call}"
|
rec_str = process(receiver)
|
||||||
|
call = brackets ? "#{rec_str}#{call}" : "#{rec_str}.#{call}"
|
||||||
end
|
end
|
||||||
|
|
||||||
call
|
call
|
||||||
|
|
|
@ -104,6 +104,15 @@ end
|
||||||
@generator.on_send(node).should == 'number.foobar(10)'
|
@generator.on_send(node).should == 'number.foobar(10)'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'when calling #[]' do
|
||||||
|
it 'returns a correctly formatted String' do
|
||||||
|
arg = Oga::Ruby::Node.new(:lit, %w{10})
|
||||||
|
node = Oga::Ruby::Node.new(:lit, %w{number})[arg]
|
||||||
|
|
||||||
|
@generator.on_send(node).should == 'number[10]'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#on_block' do
|
describe '#on_block' do
|
||||||
|
|
Loading…
Reference in New Issue