This works fine (https://carc.in/#/r/5qsl):
module Foo
def foo
end
end
class String
extend Foo
end
pp! String.foo # => nil
But this fails (https://carc.in/#/r/5qsm):
module Foo
def foo
end
end
class Array(T)
extend Foo
end
pp! Array(Int32).foo
# undefined method 'foo' for Array(Int32).class
And also this (https://carc.in/#/r/5qsn):
module Foo(T)
def foo
end
end
class Array(T)
extend Foo(T)
end
pp! Array(Int32).foo
# undefined method 'foo' for Array(Int32).class
It "works", you just cannot specify a specific type when calling:
module Foo
def foo
end
end
class Array(T)
extend Foo
end
pp! Array.foo #=> nil
In other words, the compiler error message is correct - there is no foo for Array(Int32)
Maybe the compiler should just ignore T, but it could be a breaking change if methods on specific generics were ever added (or similar mechanism).. I don't know what the plans are for generics though
however, both these work: https://carc.in/#/r/5r9j https://carc.in/#/r/5r9k
Still a bug even with self:
module Foo(T)
extend self
def foo
puts "foo"
end
end
Foo(Int32).foo
undefined method 'foo' for Foo(Int32).class
Most helpful comment
however, both these work: https://carc.in/#/r/5r9j https://carc.in/#/r/5r9k