Sha256: 239cbc74b923fc2618407cdb0e16771cca6c43b8a419cb7f340a0d660cfbc699

Contents?: true

Size: 321 Bytes

Versions: 8

Compression:

Stored size: 321 Bytes

Contents

class Fixnum
  # Returns the length of the number's string representation.
  #     0.string_length
  #     #=> 1
  #     123.string_length
  #     #=> 3
  #     -1.string_length
  #     #=> 2
  def string_length
    return 1 if self.zero?
    len = Math.log10(self.abs).floor.next
    self > 0 ? len : len.next
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
shenanigans-1.0.13 lib/shenanigans/fixnum/string_length.rb
shenanigans-1.0.11 lib/shenanigans/fixnum/string_length.rb
shenanigans-1.0.10 lib/shenanigans/fixnum/string_length.rb
shenanigans-1.0.9 lib/shenanigans/fixnum/string_length.rb
shenanigans-1.0.8 lib/shenanigans/fixnum/string_length.rb
shenanigans-1.0.7 lib/shenanigans/fixnum/string_length.rb
shenanigans-1.0.6 lib/shenanigans/fixnum/string_length.rb
shenanigans-1.0.5 lib/shenanigans/fixnum/string_length.rb