<commit_before>`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](http://clojure.org) `ns` macro and namespace system.

[![Build Status](https://secure.travis-ci.org/alandipert/rns.png)](http://travis-ci.org/alandipert/rns)

# Usage

## Importing Methods into Classes

```ruby
require 'rns'

module Arithmetic
  class << self
    def dec(n) n - 1 end
    def inc(n) n + 1 end
  end
end

module Statistics
  def self.avg(arr); arr.reduce(:+).to_f / arr.count end
end

class Main
  extend Rns.use(Arithmetic => [:inc])
  include Rns.use(Statistics => [:avg])

  def main
    puts "1+1 is #{self.class.inc 1} and the average of [1,2,3] is #{avg [1,2,3]}"
  end
end

Main.new.main
```

## Importing Methods into Blocks

```ruby
Rns::using(Arithmetic => [:inc], Statistics => [:avg]) do
  puts avg((1..10).to_a.map(&method(:inc)))
end
```

Please see the
[tests](https://github.com/alandipert/rns/tree/master/spec/rns) 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.<commit_msg>Fix README example<commit_after>`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](http://clojure.org) `ns` macro and namespace system.

[![Build Status](https://secure.travis-ci.org/alandipert/rns.png)](http://travis-ci.org/alandipert/rns)

# Usage

## Importing Methods into Classes

```ruby
require 'rns'

module Arithmetic
  class << self
    def dec(n) n - 1 end
    def inc(n) n + 1 end
  end
end

module Statistics
  def self.avg(arr); arr.reduce(:+).to_f / arr.count end
end

class Main
  extend Rns.use(Arithmetic => [:inc])
  include Rns.use(Statistics => [:avg])

  def self.incremented(n)
    "#{n} incremented is #{inc n}"
  end

  def main
    puts "#{self.class.incremented 1} and the average of [1,2,3] is #{avg [1,2,3]}"
  end
end

Main.new.main
```

## Importing Methods into Blocks

```ruby
Rns::using(Arithmetic => [:inc], Statistics => [:avg]) do
  puts avg((1..10).to_a.map(&method(:inc)))
end
```

Please see the
[tests](https://github.com/alandipert/rns/tree/master/spec/rns) 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.
{'fraction_non_alphanumeric': 0.13675213675213677, 'fraction_numerical': 0.010101010101010102, 'mean_word_length': 4.139720558882235, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1475123', 'n_tokens_mistral': 923, 'n_tokens_neox': 868, 'n_words': 285}