Giter Site home page Giter Site logo

named_proc's Introduction

Named Proc

When working with a lot of procs, naming them might become handy. It makes identifying them later easier. For an example that uses named procs, see the multi_block gem!

Currently supports CRuby only.

Setup

Add to Gemfile:

gem 'named_proc'

Named Procs

A named proc acts like a normal proc, but it has a name attribute. You create it by calling a method with the desired name on proc:

>> a = proc.even?{ |e| e.even? }
=> #<NamedProc:0x00000001ffc340@(irb):1>
>> a.name
=> :even?
>> a[42]
=> false

In the same way, you can create lambdas:

>> b = lambda.doubler{ |e| e * 2 }
=> #<NamedProc:0x000000020685e0@(irb):7 (lambda)>
>> b.name
=> :doubler
>> b[21]
=> 42
>> b.lambda?
=> true

MIT License

The original gist: https://gist.github.com/4b2f5fd0b45118e46d0f

named_proc's People

Contributors

janlelis avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.