Skip to content

Commit 18329e7

Browse files
committed
fix(pacmak): use rubyName for method and property generation to escape reserved words
1 parent 23c9aa9 commit 18329e7

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

  • packages/jsii-pacmak/lib/targets

packages/jsii-pacmak/lib/targets/ruby.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class RubyGenerator extends Generator {
291291
} else {
292292
// Behavioral interfaces in JSII can have properties and methods
293293
for (const prop of typeSpec.allProperties) {
294-
const propRubyName = toSnakeCase(prop.name);
294+
const propRubyName = this.rubyName(prop.name);
295295
this.code.line(`def ${propRubyName}()`);
296296
this.code.line(` jsii_get_property("${prop.name}")`);
297297
this.code.line(`end`);
@@ -329,7 +329,7 @@ class RubyGenerator extends Generator {
329329
return rubyParam;
330330
})
331331
.join(', ');
332-
this.code.line(`def ${toSnakeCase(method.name)}(${sigParams})`);
332+
this.code.line(`def ${this.rubyName(method.name)}(${sigParams})`);
333333
this.code.open(' ');
334334
for (const p of method.parameters) {
335335
const rubyParam = this.rubyName(p.name);
@@ -371,12 +371,12 @@ class RubyGenerator extends Generator {
371371
for (const prop of typeSpec.allProperties) {
372372
const isOptional = prop.optional ? 'true' : 'false';
373373
this.code.line(
374-
`:${toSnakeCase(prop.name)} => { kind: :property, name: "${prop.name}", is_optional: ${isOptional} },`,
374+
`:${this.rubyName(prop.name)} => { kind: :property, name: "${prop.name}", is_optional: ${isOptional} },`,
375375
);
376376
}
377377
for (const method of typeSpec.allMethods) {
378378
this.code.line(
379-
`:${toSnakeCase(method.name)} => { kind: :method, name: "${method.name}", is_optional: false },`,
379+
`:${this.rubyName(method.name)} => { kind: :method, name: "${method.name}", is_optional: false },`,
380380
);
381381
}
382382
this.code.close('}');
@@ -495,7 +495,7 @@ class RubyGenerator extends Generator {
495495
this.code.open(' ');
496496
const emittedOverridables = new Set<string>();
497497
for (const prop of overridableProps) {
498-
const rubyName = toSnakeCase(prop.name);
498+
const rubyName = this.rubyName(prop.name);
499499
if (emittedOverridables.has(rubyName)) continue;
500500
emittedOverridables.add(rubyName);
501501
const isOptional = prop.optional ? 'true' : 'false';
@@ -504,7 +504,7 @@ class RubyGenerator extends Generator {
504504
);
505505
}
506506
for (const method of overridableMethods) {
507-
const rubyName = toSnakeCase(method.name);
507+
const rubyName = this.rubyName(method.name);
508508
if (emittedOverridables.has(rubyName)) continue;
509509
emittedOverridables.add(rubyName);
510510
this.code.line(
@@ -535,7 +535,9 @@ class RubyGenerator extends Generator {
535535
})
536536
.join(', ');
537537

538-
this.code.line(`def self.${toSnakeCase(method.name)}(${sigParams})`);
538+
this.code.line(
539+
`def self.${this.rubyName(method.name)}(${sigParams})`,
540+
);
539541
this.code.open(' ');
540542
for (const p of method.parameters) {
541543
const rubyParam = this.rubyName(p.name);
@@ -572,7 +574,7 @@ class RubyGenerator extends Generator {
572574

573575
// 4. Properties
574576
for (const prop of typeSpec.allProperties) {
575-
const rubyName = toSnakeCase(prop.name);
577+
const rubyName = this.rubyName(prop.name);
576578

577579
if (prop.static) {
578580
// Static Getter
@@ -649,7 +651,7 @@ class RubyGenerator extends Generator {
649651
})
650652
.join(', ');
651653

652-
this.code.line(`def ${toSnakeCase(method.name)}(${sigParams})`);
654+
this.code.line(`def ${this.rubyName(method.name)}(${sigParams})`);
653655
this.code.open(' ');
654656
for (const p of method.parameters) {
655657
const rubyParam = this.rubyName(p.name);

0 commit comments

Comments
 (0)