Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8e88b0d

Browse files
committed
definesmethod
1 parent 5fa8a6f commit 8e88b0d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/syntax_tree/visitor/compiler.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def serialize(insn)
418418
[insn[0], iseq.local_table.offset(insn[1]), *insn[2..]]
419419
when :defineclass
420420
[insn[0], insn[1], insn[2].to_a, insn[3]]
421-
when :definemethod
421+
when :definemethod, :definesmethod
422422
[insn[0], insn[1], insn[2].to_a]
423423
when :send
424424
# For any instructions that push instruction sequences onto the
@@ -511,6 +511,11 @@ def definemethod(name, method_iseq)
511511
iseq.push([:definemethod, name, method_iseq])
512512
end
513513

514+
def definesmethod(name, method_iseq)
515+
stack.change_by(-1)
516+
iseq.push([:definesmethod, name, method_iseq])
517+
end
518+
514519
def dup
515520
stack.change_by(-1 + 2)
516521
iseq.push([:dup])
@@ -1390,7 +1395,14 @@ def visit_def(node)
13901395
end
13911396

13921397
name = node.name.value.to_sym
1393-
builder.definemethod(name, method_iseq)
1398+
1399+
if node.target
1400+
visit(node.target)
1401+
builder.definesmethod(name, method_iseq)
1402+
else
1403+
builder.definemethod(name, method_iseq)
1404+
end
1405+
13941406
builder.putobject(name)
13951407
end
13961408

test/compiler_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ class CompilerTest < Minitest::Test
364364
"def foo(bar, ...); end",
365365
"def foo(...); bar(...); end",
366366
"def foo(bar, ...); baz(1, 2, 3, ...); end",
367+
"def self.foo; end",
368+
"def foo.bar(baz); end",
367369
# Class/module definitions
368370
"module Foo; end",
369371
"module ::Foo; end",

0 commit comments

Comments
 (0)