• Home

  • Custom Ecommerce
  • Application Development
  • Database Consulting
  • Cloud Hosting
  • Systems Integration
  • Legacy Business Systems
  • Security & Compliance
  • GIS

  • Expertise

  • About Us
  • Our Team
  • Clients
  • Blog
  • Careers

  • CasePointer

  • VisionPort

  • Contact
  • Our Blog

    Ongoing observations by End Point Dev people

    Batteries Included!

    Mike Farmer

    By Mike Farmer
    April 4, 2013

    How many gems does it take to build an app? Many gems duplicate functionality that’s already in ruby core or in the standard library. Daniel Huckstep reviews some goodies that come with ruby that you could probably use to replace some of those gems.

    Basics

    • Set: Like an array but only allows unique values. Set also optimizes for the include? method so if you are calling include? a lot on your arrays and you don’t require duplicates, Set will be a much better option for you.

    • Enumerable: Gives you map, each_with_index, and all the other goodness that comes with the Enumerable class. All you need to implement is each and you get everything else in Enumerable for free.

    • Enumerator: Allows you to build your new enomerators on the fly and implement lazy loading.

    • SimpleDelegator: Inherit from SimpleDelegator and then set self and it will delegate any missing methods to the underlying class.

    • Forwardable: Forward selected methods to another object

    Performance

    • Benchmark: Allows you to measure the performance of blocks of code. It also has many different outputs and reporting formats.

    • RubyVM::InstructionSequence: Set compile options to optimize things like tailcall in recursive methods.

    • Fiddle: Allows you to call C functions in an external libraries.

    • WeakRef: (Ruby >= 2.0) Wrap whatever you pass to it to make it a candidate for garbage collection.

    Beyond

    • SecureRandom: Provides random numbers, uuid, base64, hex, etc.

    • GServer: Gives you a threaded TCP server.

    • Kernel#spawn: Provides a way to “spawn” an outside process.

    • Shellwords: Easy argument parsing for command line.

    • PStore: PStore is a simple data store that uses marshal to store objects to disk. It’s thread safe and supports transactions.

    • MiniTest: Full blown test framework built into ruby. Supports test unit and rspec like syntaxes and includes ability to mock.

    Other nice libraries: OptionParser, WEBrick, Rss, Drb, Find, Ripper, ThreadsWait, Queue / SizedQuue, MonitorMixin, Net::POP/FTP/HTTP/SMTP.

    We have a great ecosystem of gems, but there’s already a lot of what we use gems for already in the Ruby core and standard library.

    conference ruby


    Comments