Closed thbar closed 8 years ago
:+1:
The yield
construct is afaik not possible to achieve (see discussion). Passing a block as a param should work though. That, or using enumerables/enumerators.
A magic process
method can do the trick.
source do
File.open(source_file) do |file|
Oj.load(file).each do |row|
process row
end
end
end
@Radagaisus good point - I'll try that out when I look more closely at this again. Thanks!
While this seems a "nice to have" idea, in months of production use of Kiba, I never truly felt the actual need to have that. I always end up writing sources as real classes, without feeling any urge to do differently. Closing for now, I'll re-open if I change my mind!
I find myself wrapping sources like this:
where I'd prefer to be able to write this (at least for one-off scripts):
Here the semantic would be that the block must yield each row. Another possible semantic would be this:
where the block is expected to return something that would respond to
.each
.Maybe both semantics would be nice to have, with maybe a different keyword or some kind of parameter.
I must think with more depth about this for now, just dropping a note.