ruby - A method for creating a huge number -


rubymonk makes point on how can use underscores convenience write large numbers can become difficult read without demarcation.

their task is: try using underscores make huge, readable number. provide code:

def describe(something)   puts "i a: #{something.class} , like: #{something}" end  def big_num   # create huge number end  describe(big_num) 

could explain how go creating huge number? according error messages below, have use underscores in code make pass.

rubymonk expects object of class bignum, part of standard ruby library. documentation:

bignum objects hold integers outside range of fixnum. bignum objects created automatically when integer calculations otherwise overflow fixnum.

so have create number bigger fixnum can handle. example, pass rubymonk's spec:

def big_num   5_000_000_000_000_000_000_000 end 

because number bigger fixnum can handle, ruby automagically returns bignum instead. example, try running this:

5_000_000_000.class # => fixnum 5_000_000_000_000_000_000_000.class # => bignum  

Comments