Tag Archives: Ruby

A Batch Encoding Convertor for Text File and ID3 Tag

encoding conventor

When copying some of my old project files from Windows 7, the origin system text file encoding made some troubles for me. So in December, I wrote a small tool to help me out. But before days, the same problem came out again when the old mp3 ID3 tagged files met the iTunes. Therefore, I extended the tool to automatically convert the mp3 files to the specified encoding. I used the ID3iconv to help with the tag editing.

Continue reading

Why not ruby replace the Block with lambda?

Where there is a will, there is a way. Some times when you are programming in C# or python, you may think about is there a way to break out of a function block to it’s parent scope?

We learned that in C we could use goto to jump around the codes. That’s a great tool when you need to jump out of deep nested loops. But you can’t jump out of a function with this tricky tool. If you learned about POSIX C, the longjump can meet the need, though it’s intended to easier the complexity in error handling. Requirement like jumping out of a function is really rare when coding. We always can find out a solution. Such as try catch in C++ or C#.

Lua code fragment below, you can’t stop the code from going through all the numbers. The permutation is a system predefined function, and we cannot modify it.

But Ruby can complete the task with Block like below:

The differences make the existence of things reasonable.