To get factorial of n
(1..n).inject :*
To take care of zero
(1..n).inject(1, :*)
More Related Contents:
- Ruby factorial function
- Converting an array of numbers to characters ruby [closed]
- Why are exclamation marks used in Ruby methods?
- Installed Ruby 1.9.3 with RVM but command line doesn’t show ruby -v
- Difference between class variables and class instance variables?
- How to select unique elements
- Where and how is the _ (underscore) variable specified?
- What is “main” in Ruby?
- How to modify PATH for Homebrew?
- EventSource / Server-Sent Events through Nginx
- What exactly is the singleton class in ruby?
- How to install PostgreSQL’s pg gem on Ubuntu?
- Difference between various variables scopes in ruby
- Creating matrix with `Array.new(n, Array.new)`
- Mac user and getting WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 2.7.3
- Unexpected keyword_end error, yet syntax seems fine
- Valid email address regular expression? [duplicate]
- list of ruby operators that can be overridden/implemented
- Ruby objects and JSON serialization (without Rails)
- Ruby – Difference between Array#
- ERROR: While executing gem … (Errno::EPERM) Operation not permitted [duplicate]
- ERROR: While executing gem … (Gem::FilePermissionError)
- class
- How can I generate zip file without saving to the disk with Ruby?
- Convert unicode codepoint to string character in Ruby
- Ruby Fibonacci algorithm
- How to select nodes by matching text
- How can I intercept method call in ruby?
- Ruby : How to write a gem? [closed]
- All factors of a given number