Comments (7)
I think I got the point.
class Foo
def each
yield 1
yield 2
end
include Enumerable
end
Foo.new.each # => error!!
Okay, we need to revise the definition of the interface!
from rbs.
@soutaro just for clarity, I'm not arguing for a revision of the existing one, but to add a new one. The reasoning is, the current _Each
already describes the requirement for implementing a class decorated with Enumerable
. But an _EnumEach
is common enough (IMO) to warrant defining it as a common interface (as most core and stdlib enumerables already do it).
from rbs.
Could you show me an example that requires no-block-given version?
from rbs.
Enumerable#each
is the most obvious example, I think. For example:
:0> [].each
=> #<Enumerator: []:each>
Currently, the way it's defined, the rbs definition doens't match this case.
from rbs.
Enumerable#each
is the most obvious example, I think. For example::0> [].each => #<Enumerator: []:each>
Currently, the way it's defined, the rbs definition doens't match this case.
This is the definition you are looking for.
It's basically correct, except the second should return ::Enumerator[Elem, self]
, so I opened a PR to fix that.
from rbs.
I was actually arguing for this definition to be part of a common interface, instead of being rewritten in every project implementing each
with no block, which I think it's common enough, wouldn't you agree?
from rbs.
It could definitely be useful as a shorthand, but maybe should be named something different like _Iterable
?
I think _MethodName
should be restricted to interfaces that implement that method_name
minimally. So @soutaro's point was that if you want to accept that an object that implements each
(which is what the name _Each
suggests), then you probably don't want to impose that each
without a block work, only that each
with a block does.
If you want to specify that your class implements each
"correctly", then yes, you should have these two interfaces and a shorthand might be useful. I'm not sure how often this is, and how often that method is necessarily named each
...
from rbs.
Related Issues (20)
- Somehow add metaprogramming to type parameters HOT 1
- Add Support for Non-Symbol Keyowrds
- Add support for `__END__` in rbs files HOT 1
- Add support for `alias $x $y` HOT 2
- Add support for `undef` HOT 2
- Thread/Fiber/Kernel#raise is incorrectly labeled HOT 3
- ConditionVariable#wait signature return is incorrect HOT 1
- TCPServer.new type signature incorrect
- `Proc::new` is the one that take the block, not `Proc#initialize`
- rbs/test: stack level too deep when calling super from prepend HOT 1
- "singleton(class with this mixin)" is not supported
- [RBS::Test] Cannot call `super` in block
- How to deal with gems with integrations
- Incorrrect signatures for ruby 3.3.0
- Type signature failures in net-http
- support * in tuples HOT 3
- Position of RBS::Location should be byte length HOT 3
- `rbs collection install` fails with parse error HOT 8
- Identify and skip `development` dependencies
- Support type narrowing HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rbs.