Giter VIP home page Giter VIP logo

filtration's Introduction

Filtration

Filtration is a clean, lightweight way to filter arguments going into and coming out of methods (similar to decorators in Python).

Usage

Example:

class Bar

  def foo(x)
    x + 2
  end

  def foo_too(x)
    x + 2
  end

  def foo_as_well(x)
    "#{x.to_s} to the max!"
  end

  def foo_forever(x)
    "#{x.to_s} to the max!"
  end

end

class Foo < Bar

  prefilter(:foo){|x| x * 2}

  postfilter(:foo_too){|x| x * 2}

end

randy = Foo.new
randy.foo(2) #=> (x * 2) + 2 = 6 (for x = 2)
randy.foo_too(2) #=> (x + 2) * 2 = 8 (for x = 2)

class AnotherFoo < Bar

  prefilter :foo, :double

  postfilter :foo_too, :double

  def double(x)
    x * 2
  end

end

savage = AnotherFoo.new
savage.foo(2)  #=> (x * 2) + 2 = 6
savage.foo_too(2) #=> (x + 2) * 2 => 8

class YetAnotherFoo < Bar

  prefilter :foo_as_well, &:upcase

  postfilter :foo_forever, &:upcase

end

machoman = YetAnotherFoo.new
machoman.foo_as_well('filtration') #=> "#{x.upcase} to the max!" = 'FILTRATION to the max!'
machoman.foo_forever('filtration') #=> "#{x} to the max!".upcase = 'FILTRATION TO THE MAX!'

Requirements

Filtration stands on its own!

Development

RSpec is used for testing, with SimpleCov for code coverage.

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.