Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ripar

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ripar

  • 0.0.3
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Ripar Gem Version Build Status

Think riparian. Think old man river, he jus' keep on rollin'. Think rive. Also river, reaver, repair, reaper.

Tear chained method calls apart, put them in a block, and return the block value. eg

Before:

  result = values.select{|x| x.name =~ /Jo/}.map{|x| x.count}.inject(0){|s,x| s + x}

After:

  result = values.rive do
    select{|x| x.name =~ /Jo/}
    map{|x| x.count}
    inject(0){|s,x| s + x}
  end

This is also a little different to instance_eval, because the following will work:

  outside_block_regex = /Wahoody-hey/

  result = values.rive do
    select{|x| x.name =~ outside_block_regex}
    map{|x| x.count}
    inject(0){|s,x| s + x}
  end

Warning this can have some rare but weird side effects:

  • will probably break on classes that have defined method_missing, but not respond_to_missing
  • an outside variable with the same name as an inside method taking in-place hash argument will cause a syntax error.

But you can obviate all of that by just using the safe syntax:

  outside_block_regex = /Wahoody-hey/

  result = values.rive do |vs|
    vs.select{|x| x.name =~ outside_block_regex}
    vs.map{|x| x.count}
    vs.inject(0){|s,x| s + x}
  end

Or using the magic disambiguaters:

  select = /Wahoody-hey/

  result = values.rive do
    __inside__.select{|x| x.name =~ __outside__.select}
    map{|x| x.count}
    inject(0){|s,x| s + x}
  end

Installation

Add this line to your application's Gemfile:

gem 'ripar'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ripar

Usage

In your class

class YourChainableThing
  include Ripar
end

yct = YourChainableThing.new.rive do
  # operations
end

In a singleton

o = Object.new
class << o
  include Ripar
end

The mostest lightweightiest

o = Object.new.extend(Ripar)

Monkey-patch

class Object
  include Ripar
end

Contributing

The standard github pull request dance:

  1. Fork it ( http://github.com//ripar/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

PS

Thing = Struct.new :name, :count
values = [
  Thing.new('John', 20),
  Thing.new('Joe', 7),
  Thing.new('Paul', 3),
  Thing.new('James', 3),
  Thing.new('Wahoody-heydi-dude', 3.141527),
]

FAQs

Package last updated on 07 May 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc