Skip to content
This repository was archived by the owner on May 18, 2026. It is now read-only.

Commit c76d860

Browse files
takaokoujiGemini
andcommitted
feat: use new meta-comment format @ruby:method: for print/puts/p
- Update RubyToBlocksConverter to use @ruby:method: directive - Update RubyGenerator to recognize @ruby:method: and filter @ruby: prefix - Remove legacy @smalruby: prefix support and tests as compatibility is not required - Update unit tests to reflect format changes 🤖 Generated with [Gemini Code](https://gemini.google.com/code) Co-Authored-By: Gemini <noreply@google.com>
1 parent 3ffda3c commit c76d860

5 files changed

Lines changed: 21 additions & 19 deletions

File tree

src/lib/ruby-generator/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ RubyGenerator.scrub_ = function (block, code) {
356356
let commentCode = '';
357357
if (!this.isConnectedValue(block)) {
358358
let comment = this.getCommentText(block);
359-
if (comment && !comment.startsWith('@smalruby:')) {
359+
if (comment && !comment.startsWith('@ruby:')) {
360360
commentCode += `${this.prefixLines(comment, '# ')}\n`;
361361
}
362362
const inputs = this.getInputs(block);
@@ -367,7 +367,7 @@ RubyGenerator.scrub_ = function (block, code) {
367367
comment = this.allNestedComments(childBlock);
368368
if (comment) {
369369
const filteredComment = comment.split('\n')
370-
.filter(line => !line.startsWith('@smalruby:'))
370+
.filter(line => !line.startsWith('@ruby:'))
371371
.join('\n');
372372
if (filteredComment.trim().length > 0) {
373373
commentCode += this.prefixLines(filteredComment, '# ');

src/lib/ruby-generator/looks.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ export default function (Generator) {
1313
Generator.looks_say = function (block) {
1414
const message = Generator.valueToCode(block, 'MESSAGE', Generator.ORDER_NONE) || Generator.quote_('');
1515
const comment = Generator.getCommentText(block);
16-
if (comment && comment.startsWith('@smalruby:')) {
17-
const methodName = comment.substring(10);
18-
if (['print', 'puts', 'p'].includes(methodName)) {
19-
return `${methodName}(${message})\n`;
16+
if (comment) {
17+
if (comment.startsWith('@ruby:method:')) {
18+
const methodName = comment.substring(13);
19+
if (['print', 'puts', 'p'].includes(methodName)) {
20+
return `${methodName}(${message})\n`;
21+
}
2022
}
2123
}
2224
return `say(${message})\n`;

src/lib/ruby-to-blocks-converter/looks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const LooksConverter = {
8585
if (!converter._isNumberOrStringOrBlock(args[0])) return null;
8686

8787
const block = createBlockWithMessage.call(converter, 'looks_say', args[0], 'Hello!');
88-
block.comment = converter.createComment(`@smalruby:${methodName}`, block.id, 200, 0);
88+
block.comment = converter.createComment(`@ruby:method:${methodName}`, block.id, 200, 0);
8989
return block;
9090
});
9191
});

test/unit/lib/ruby-generator/looks.test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,72 +27,72 @@ describe('RubyGenerator/Looks', () => {
2727
expect(RubyGenerator.looks_say(block)).toEqual(expected);
2828
});
2929

30-
test('with @smalruby:print', () => {
30+
test('with @ruby:method:print', () => {
3131
const block = {
3232
id: 'block-id',
3333
opcode: 'looks_say',
3434
inputs: {
3535
MESSAGE: {}
3636
}
3737
};
38-
RubyGenerator.cache_.comments['block-id'] = { text: '@smalruby:print' };
38+
RubyGenerator.cache_.comments['block-id'] = { text: '@ruby:method:print' };
3939
RubyGenerator.valueToCode = jest.fn().mockReturnValue('"Hello!"');
4040
const expected = 'print("Hello!")\n';
4141
expect(RubyGenerator.looks_say(block)).toEqual(expected);
4242
});
4343

44-
test('with @smalruby:puts', () => {
44+
test('with @ruby:method:puts', () => {
4545
const block = {
4646
id: 'block-id',
4747
opcode: 'looks_say',
4848
inputs: {
4949
MESSAGE: {}
5050
}
5151
};
52-
RubyGenerator.cache_.comments['block-id'] = { text: '@smalruby:puts' };
52+
RubyGenerator.cache_.comments['block-id'] = { text: '@ruby:method:puts' };
5353
RubyGenerator.valueToCode = jest.fn().mockReturnValue('"Hello!"');
5454
const expected = 'puts("Hello!")\n';
5555
expect(RubyGenerator.looks_say(block)).toEqual(expected);
5656
});
5757

58-
test('with @smalruby:p', () => {
58+
test('with @ruby:method:p', () => {
5959
const block = {
6060
id: 'block-id',
6161
opcode: 'looks_say',
6262
inputs: {
6363
MESSAGE: {}
6464
}
6565
};
66-
RubyGenerator.cache_.comments['block-id'] = { text: '@smalruby:p' };
66+
RubyGenerator.cache_.comments['block-id'] = { text: '@ruby:method:p' };
6767
RubyGenerator.valueToCode = jest.fn().mockReturnValue('"Hello!"');
6868
const expected = 'p("Hello!")\n';
6969
expect(RubyGenerator.looks_say(block)).toEqual(expected);
7070
});
7171

72-
test('with unknown @smalruby: tag defaults to say', () => {
72+
test('with unknown @ruby: tag defaults to say', () => {
7373
const block = {
7474
id: 'block-id',
7575
opcode: 'looks_say',
7676
inputs: {
7777
MESSAGE: {}
7878
}
7979
};
80-
RubyGenerator.cache_.comments['block-id'] = { text: '@smalruby:unknown' };
80+
RubyGenerator.cache_.comments['block-id'] = { text: '@ruby:unknown' };
8181
RubyGenerator.valueToCode = jest.fn().mockReturnValue('"Hello!"');
8282
const expected = 'say("Hello!")\n';
8383
expect(RubyGenerator.looks_say(block)).toEqual(expected);
8484
});
8585
});
8686

8787
describe('scrub_ (meta-comment filtering)', () => {
88-
test('should filter out @smalruby: comments', () => {
88+
test('should filter out @ruby: comments', () => {
8989
const block = {
9090
id: 'block-id',
9191
opcode: 'looks_say',
9292
inputs: {},
9393
next: null
9494
};
95-
RubyGenerator.cache_.comments['block-id'] = { text: '@smalruby:print' };
95+
RubyGenerator.cache_.comments['block-id'] = { text: '@ruby:method:print' };
9696
RubyGenerator.getInputs = jest.fn().mockReturnValue({});
9797
RubyGenerator.isConnectedValue = jest.fn().mockReturnValue(false);
9898
RubyGenerator.getBlock = jest.fn().mockReturnValue(null);
@@ -101,7 +101,7 @@ describe('RubyGenerator/Looks', () => {
101101
const code = 'print("Hello!")\n';
102102
const result = RubyGenerator.scrub_(block, code);
103103

104-
// Should NOT contain the comment since it starts with @smalruby:
104+
// Should NOT contain the comment since it starts with @ruby:
105105
expect(result).toEqual('print("Hello!")\n');
106106
});
107107

test/unit/lib/ruby-to-blocks-converter/looks.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ describe('RubyToBlocksConverter/Looks', () => {
12101210

12111211
const commentId = block.comment;
12121212
expect(converter._context.comments[commentId]).toBeDefined();
1213-
expect(converter._context.comments[commentId].text).toEqual(`@smalruby:${method}`);
1213+
expect(converter._context.comments[commentId].text).toEqual(`@ruby:method:${method}`);
12141214
expect(converter._context.comments[commentId].x).toEqual(200);
12151215
expect(converter._context.comments[commentId].y).toEqual(0);
12161216
expect(converter._context.comments[commentId].minimized).toBe(true);

0 commit comments

Comments
 (0)