diff --git a/lib/ruby/block_statement.rb b/lib/ruby/block_statement.rb index 373622ee..5050d397 100644 --- a/lib/ruby/block_statement.rb +++ b/lib/ruby/block_statement.rb @@ -1,12 +1,11 @@ -module Vool +module Ruby class BlockStatement < Statement - attr_reader :args , :body , :clazz + attr_reader :send , :args , :body - def initialize( args , body , something_really_else) - @args , @body = args , body + def initialize( send , args , body ) + @send , @args , @body = send , args , body raise "no bod" unless @body - @clazz = clazz end def to_vool diff --git a/lib/ruby/ruby_compiler.rb b/lib/ruby/ruby_compiler.rb index f9427962..f839fee6 100644 --- a/lib/ruby/ruby_compiler.rb +++ b/lib/ruby/ruby_compiler.rb @@ -41,8 +41,7 @@ module Ruby sendd = process(block_node.children[0]) args = process(block_node.children[1]) body = process(block_node.children[2]) - sendd.add_block BlockStatement.new(args , body) - sendd + BlockStatement.new(sendd , args , body) end def on_yield(node) @@ -177,7 +176,7 @@ module Ruby IfStatement.new( process(condition) , if_true , if_false ) end - def on_send statement + def on_send( statement ) kids = statement.children.dup receiver = process(kids.shift) || SelfExpression.new name = kids.shift diff --git a/test/ruby/test_block_statement.rb b/test/ruby/test_block_statement.rb index 072d1eb1..8c9c21d2 100644 --- a/test/ruby/test_block_statement.rb +++ b/test/ruby/test_block_statement.rb @@ -1,30 +1,28 @@ require_relative "helper" module Ruby - class TestBlockStatementX < MiniTest::Test + class TestBlockStatement < MiniTest::Test include RubyTests def setup() input = "plus_one{|arg1| arg1 + 1 } " @lst = compile( input ) end - def test_method - assert_equal SendStatement , @lst.class - end def test_block - assert_equal BlockStatement , @lst.block.class + assert_equal BlockStatement , @lst.class + end + def test_send + assert_equal SendStatement , @lst.send.class end - def test_method_name - assert_equal :plus_one , @lst.name + assert_equal :plus_one , @lst.send.name end - def test_block_args - assert_equal [:arg1] , @lst.block.args + assert_equal [:arg1] , @lst.args end def test_block_body - assert_equal SendStatement , @lst.block.body.class - assert_equal 1 , @lst.block.body.arguments.length + assert_equal SendStatement , @lst.body.class + assert_equal 1 , @lst.body.arguments.length end end end