Implementing the *ect Methods in Terms of Inject

Josh told me today that one

way to see if someone is any good at Ruby is to have them implement

the *ect methods in terms of inject. This isn’t a fool-proof method,

and I’m also not concerned about it’s

screening value

as much as I am simply interested in how to do it. Most importantly,

do I meet Josh’s standards?

(As Nick pointed out,

anyone who’s spent more than 5 minutes functional programming would

laugh at this. I’m a newbie.)

Before I show my code, I’m going to give you the opportunity to go try

it for yourself. Write custom #detect, #select, #reject, and #collect

methods in terms of Enumerable#inject.

Here’s a little RSpec example that will let you automatically verify

your implementation:

And now for my implementation:

How did you do it?

You know that folder you’ve got filled with coding projects that never made it off the ground?

  • code snippets that could become libraries, with a few tests
  • libraries that could become gems, with some new documentation
  • gems that could become side projects, with a bit of refactoring
  • side projects that could become products, with the right game plan

You start each project with the best intentions, even big plans for some of them… but then life gets in the way, and you focus your attention on more important things. Then when you get some free time you dream up another project, and the cycle repeats itself.

You know that you can ship – you get all kinds of other projects out the door at work. Why do your open source ideas collect dust and regret?

The rules you apply to get stuff done at work don’t apply to your hobby projects. If you take the objective-driven approach you use in your work and try to use it on your hobby projects, you will continue to fall short of your goals – and keep piling on the guilt.

You can break the cycle, by launching one of your open source project ideas. You can push the spiral upward, by getting one project out the door and moving on to the next one.

You just need to learn a few skills and techniques that will help you dig in to your project graveyard and bring your projects to life.

Get Hack Your Open Source Project for FREE and you will:

  • set up your environment for success
  • quickly come up with a plan – and then put it in to action
  • ship your first version today – and keep improving it
  • get more people involved in your project
  • Please enter your name and email below so I can send you Hack Your Open Source Project, absolutely free:

    (Visited 4 times, 1 visits today)

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    8 × = thirty two

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>