[Library] thriving Ruby extension Library

Source: Internet
Author: User

Since rails was booming, the Ruby community has grown a lot better than before (younger brother, I also learned Ruby because of rails, various Ruby extension libraries have sprung up. Their features are that their versions are low (rarely 1.0) and their names are personalized, the main purpose is to enhance or replace Ruby's built-in standard library. The following lists some of

Rio: Ruby I/O comfort class

Rio is a ruby built-in Io class packaging. Its main function is to operate files, capture webpages, compress and decompress, process CSV and other IO operations. The current version is 0.3.7, rio is easy to use
Example:

Copy or add content to a string object

 rio('afile') > astring      # copy rio('afile') >> astring     # append

Copy or add content to an object

 rio('afile') < astring      # copy rio('afile') << astring     # append

His official site provides detailed examples. Do not miss out if you are a friend who often want to maintain files on Linux.

CommandLine: command line enhancement

CommandLine is a library that simplifies the command line interface. It directly replaces the built-in optparser to parse user parameters and automatically prints standard usage/version/help prompts, it also supports three formats: Unix, GNU, and X toolkit.
It's easy to use commanline. just inherit its CommandLine: application.
Example:

class App < CommandLine::Application    def initialize      version           "0.0.1"      author            "Author Name"      copyright         "2005, Jim Freeze"      synopsis          "[-dhV] param_file out_file"      short_description "A simple app example that takes two arguments."      long_description  "app5 is a simple application example that supports "+                        "three options and two commandline arguments."      option :version      option :debug      option :help      expected_args   :param_file, :out_file    end    def main      puts "main called"      puts "@param_file = #{@param_file}"      puts "@out_file   = #{@out_file}"    end  end

By executing the ruby XXX. RB-H command, you can immediately see that the standard help is printed.

  NAME      xxx.rb - A simple app example that takes two arguments.  DESCRIPTION      xxx.rb is a simple application example that supports three options      and two commandline arguments.  OPTIONS      --version,-V          Displays application version.      --debug,-d          Sets debug to true.      --help,-h          Displays help page.  AUTHOR:  Author Name  Copyright (c) 2005, Jim Freeze
Fastercsv: a faster and simpler CSV Library

As the name suggests, the CSV processing library is faster. I can see that the evaluation on maillist is 10 times faster (the built-in evaluation is too slow, that is why fastercsv is faster than 10 times or slower than python. At the same time, it is easier to use than built-in CSV (unless you don't know what CSV is)
For example, reading a CSV file

  FasterCSV.foreach("path/to/file.csv") do |row|    puts row[0]    puts row[2]  end

Support reading CVS files using Headers

Fastercsv. foreach ("path/to/file.csv",: headers => true) Do | row | # The first line is header, puts row ['fielda'] puts row ['field'] end is automatically ignored.

Please note that it uses require 'faster _ csv', and the class name is fastercsv, which is not very consistent with Ruby naming rules.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.