Skip to content

Commit

Permalink
Add instnace var assignment and access
Browse files Browse the repository at this point in the history
  • Loading branch information
Josep M. Bach committed Feb 27, 2012
1 parent 8365816 commit 930a4bf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/to_source/visitor.rb
Expand Up @@ -26,6 +26,15 @@ def local_variable_access(node, parent)
emit node.name
end

def instance_variable_assignment(node, parent)
emit "%s = " % node.name
node.value.lazy_visit self, node
end

def instance_variable_access(node, parent)
emit node.name
end

def fixnum_literal(node, parent)
emit node.value.to_s
end
Expand Down
8 changes: 8 additions & 0 deletions test/to_source/visitor_test.rb
Expand Up @@ -19,10 +19,18 @@ def test_local_assignment
assert_source "foo = 1"
end

def test_ivar_assignment
assert_source "@foo = 1"
end

def test_local_access
assert_source "foo = 1\nfoo"
end

def test_ivar_access
assert_source "@foo"
end

def test_constant_access
assert_source "Rubinius"
end
Expand Down

0 comments on commit 930a4bf

Please sign in to comment.