Skip to content

Commit

Permalink
Support NODE_IVAR
Browse files Browse the repository at this point in the history
  • Loading branch information
S-H-GAMELINKS committed Aug 19, 2024
1 parent 7d37472 commit 8555d5e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ext/mjollnir/mjollnir.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,16 @@ node_args_to_hash(const NODE *node)
return result;
}

static VALUE
node_ivar_to_hash(const NODE *node)
{
VALUE result = rb_hash_new();

rb_hash_aset(result, rb_str_new2("vid"), ID2SYM(RNODE_IVAR(node)->nd_vid));

return result;
}

static VALUE
ast_to_hash(const NODE *node)
{
Expand Down Expand Up @@ -344,6 +354,11 @@ ast_to_hash(const NODE *node)
rb_hash_aset(result, rb_str_new2("NODE_BEGIN"), node_begin_to_hash(node));
return result;
}
case NODE_IVAR: {
VALUE result = rb_hash_new();
rb_hash_aset(result, rb_str_new2("NODE_IVAR"), node_ivar_to_hash(node));
return result;
}
case NODE_INTEGER:
case NODE_FLOAT:
case NODE_RATIONAL:
Expand Down
22 changes: 22 additions & 0 deletions test/mjollnir/parse_ivar_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require 'test_helper'

class ParseIvarTest < Minitest::Test
def test_parse_ivar
result = Mjollnir.parse('@mjollnir')

expected = {
'NODE_SCOPE' => {
'args' => nil,
'body' => {
'NODE_IVAR' => {
'vid' => :@mjollnir
}
}
}
}

assert_equal expected, result
end
end

0 comments on commit 8555d5e

Please sign in to comment.