Socket
Book a DemoInstallSign in
Socket

rns

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rns

0.0.7
bundlerRubygems
Version published
Maintainers
1
Created
Source

rns, which stands for "Ruby namespaces", is a small library for using classes and modules as packages of functions in order to support functional programming in Ruby. It is inspired by Clojure's ns macro and namespace system.

Build Status

Usage

Importing Methods into Classes

require 'rns'

Arithmetic = Rns do
  def dec(n) n - 1 end
  def inc(n) n + 1 end
end

Statistics = Rns do
  def avg(arr) arr.reduce(:+).to_f / arr.count end
end

class Main
  Funcs = Rns(Statistics, Arithmetic => [:inc]) do
    def incremented_avg(nums)
      avg nums.map(&method(:inc))
    end
  end

  def main
    nums = [1, 2, 3]
    puts "The average of #{nums.inspect} incremented is: #{Funcs.incremented_avg nums}"
  end
end

Main.new.main

Please see the tests for more usage examples.

Rationale

Ruby has good functional programming support, but the class and module system doesn't lend itself to organizing and accessing functions. With rns I hope to make it at least slightly easier to build Ruby programs primarily out of pure functions.

Thanks

To Sam Umbach for helping me tame the eigenclass, and to my employer Relevance for indulging me with time to work on free software.

FAQs

Package last updated on 25 Jul 2012

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.