0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
It allows you to create simple blocks by using underscore symbol
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

RubyUnderscore

Closures are very useful tools, and ruby Enumerable mixin makes them even more useful.

However, as you decompose more and more your iterations into a sequence of maps, selects, rejects, group_bys and reduces, more commonly you see simple blocks such as:

dates.select { |d| d.greater_than(old_date) }
collection.map { |x| x.invoke }
classes.reject { |c| c.subclasses.include?(Array) }

RubyUnderscore modify classes so that you can also use a short notation for simple closures. With such, the above examples can be written as:

dates.select _.greater_than old_date
collection.map _.invoke
classes.reject _.subclasses.include? Array

Just replace the iterating argument with the underscore symbol (_), and ditch the parenthesis. More info

Quick Example

The example consists of getting all instance methods of String, Array, Class that end with 'd?'

require 'ruby_underscore'

class MethodFinder
  include RubyUnderscore::Base

  def find_interrogation_methods
    [String, Array, Class].map(_.public_instance_methods.grep /d\?$/).flatten.sort.uniq
  end
end
p MethodFinder.new.find_interrogation_methods

Using Ruby Underscore

As in the example above, simply by including the module include RubyUnderscore::Base on the class, all methods (class methods as well) will allow you to use the underscore symbol to write simple blocks.

Meta

Created by Daniel Ribeiro

Released under the MIT License: http://www.opensource.org/licenses/mit-license.php

http://github.com/danielribeiro/RubyUnderscore