Created
December 23, 2008 06:33
-
-
Save fairchild/39271 to your computer and use it in GitHub Desktop.
A nice example of Meta programing from the earworm project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| 'ogg' => Audio::OGG::Decoder, | |
| 'mp3' => Audio::MPEG::Decoder, | |
| }.each do |type,klass| | |
| define_method(:"decode_#{type}") do |filename| | |
| reader = klass.new | |
| name = File.join(Dir::tmpdir, | |
| "#{File.basename(filename, ".#{type}")}.wav") | |
| File.open(filename, 'rb') { |input| | |
| File.open(name, 'wb') { |tmpfile| | |
| reader.decode(input, tmpfile) | |
| } | |
| } | |
| name | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment