From 4a3d11c31d99c7837ab5f7b9d0486f6fb09a1459 Mon Sep 17 00:00:00 2001 From: David Baker Effendi Date: Mon, 21 Oct 2024 12:33:05 +0200 Subject: [PATCH] Added `:def` to `:sclass` --- Gemfile.lock | 2 +- lib/ruby_ast_gen/node_handling.rb | 1 + spec/ruby_ast_gen_spec.rb | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 4275f1a..95fb442 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ruby_ast_gen (0.15.0) + ruby_ast_gen (0.16.0) GEM remote: https://rubygems.org/ diff --git a/lib/ruby_ast_gen/node_handling.rb b/lib/ruby_ast_gen/node_handling.rb index 5d1dd5f..d9222bb 100644 --- a/lib/ruby_ast_gen/node_handling.rb +++ b/lib/ruby_ast_gen/node_handling.rb @@ -91,6 +91,7 @@ def self.add_node_properties(node_type, base_map, file_path) base_map[:body] = children[2] when :sclass base_map[:name] = children[0] + base_map[:def] = children[1] base_map[:body] = children[2] when :module base_map[:name] = children[0] diff --git a/spec/ruby_ast_gen_spec.rb b/spec/ruby_ast_gen_spec.rb index 090b719..b152831 100644 --- a/spec/ruby_ast_gen_spec.rb +++ b/spec/ruby_ast_gen_spec.rb @@ -56,4 +56,28 @@ class Foo ast = RubyAstGen::parse_file(temp_file.path, temp_name) expect(ast).not_to be_nil end + + it "should create a singleton object body successfully" do + code(<<-CODE) +class C + class << self + def f(x) + x + 1 + end + end +end + CODE + ast = RubyAstGen::parse_file(temp_file.path, temp_name) + expect(ast).not_to be_nil + end + + it "should create an operator assignment successfully" do + code(<<-CODE) +def foo(x) + x += 1 +end + CODE + ast = RubyAstGen::parse_file(temp_file.path, temp_name) + expect(ast).not_to be_nil + end end