Closed soutaro closed 1 week ago
Example with just Ruby stdlib:
module Foo
instance_eval do
# @rbs module ClassMethods
def foo = 123
end
end
Implemented in #69, with a minor syntax change.
module Foo
# The @rbs module annotation is given above the block call.
# @rbs module ClassMethods
class_methods do
def foo = 123
end
end
@ParadoxV5 By the way, the @rbs module
syntax would not be sufficient for the instance_eval
example.
What we need is to do it in singleton class context. Not defining another module for the block.
module Foo
# We don't want ClassMethods module...
module ClassMethods
def foo: () -> untyped
end
def self.foo: () -> untyped # This is expected
end
Maybe we need @rbs class <<self
???
We could just not support it.
Is there a concrete reason one’d use instance_eval do
over class << self
in Ruby?
Some methods allow defining methods to another class inside blocks.
I plan to introduce
@rbs class C
and@rbs module M
commands, that wraps the contents of the block inside aclass
/module
declaration.(
end
is missing, but we know it's acceptable from Haml.)