tribusonz-2 / rb_wave

Wave library for Ruby
MIT License
0 stars 0 forks source link

The subject that desirable file converter implementation without file opener/closer #7

Open tribusonz-2 opened 1 month ago

tribusonz-2 commented 1 month ago
pcms = Wave::RIFF.read(fname) # => *Wave::PCM

I personally found it hard to understand the idea of the behavior:​reading a file, analyzing the data, and then closing the file.
We want definition the method, it will look like the code above.
One small issue is that if a critical IO error occurs, we have no control over it, or even if we do, no information about it.

"Tap" is preferable here, as tap means "insert" in object-oriented terms.

pcms = Array.new 

File.open(fname, "rb") do |f|
  pcms = Wave::RIFF.read(f)
end

pcms #=> *Wave::PCM

We call this implementation model "tapping".