# Root Module (code)

**URL:** <https://rubytalk.org/t/root-module-code/58761>\
**Category:** ruby-talk\
**Created:** [3 June 2010 16:55 UTC](https://rubytalk.org/t/root-module-code/58761 "2010-06-03T16:55:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jzakiya](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jzakiya](https://rubytalk.org/u/jzakiya)\
**Post date:** [3 June 2010 16:55 UTC](https://rubytalk.org/t/root-module-code/58761/1 "2010-06-03T16:55:10Z")

</div>

Module 'Roots' provides two methods 'root' and 'roots'  
which will find all the nth roots for all real, and complex  
, numerical types.

View and download code here:

> <https://gist.github.com/jzakiya/422636>

Install process:

Place module file 'roots.rb' into 'lib' directory of ruby  
version.  
Then from irb session, or a source code file, do:

require 'roots'

#For extended math features also do: require 'mathn'

#Mixin 'Roots' into class Numeric

class Numeric; include Roots end

Can now find nth root(s) of all numerical types:

\<floats\>.root(s) n, opt  
\<integer\>.root(s) n, opt  
\<rational\>.root(s) n, opt  
\<complex\>.root(s) n, opt  
\<bigdecimal\>.root(s) n, opt

It would be nice for this capability to be considered for Ruby core.

Jabari Zakiya
