Project

named_proc

0.0
No release in over 3 years
Low commit activity in last 3 years
NamedProc: Like anonymous procs, but have a name. Example: lambda.codebrawl {} # creates an empty lambda with the name :codebrawl
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.2
~> 13.0
 Project Readme

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