Skip to content

Latest commit

 

History

History
31 lines (27 loc) · 533 Bytes

regexp_basics_is_it_a_digit.md

File metadata and controls

31 lines (27 loc) · 533 Bytes

Description

Implement String#digit? (in Java StringUtils.isDigit(String)), which should return true if given object is a digit (0-9), false otherwise.

class String
  def digit?
    # your code goes here
  end
end

My Solution

class String
  def digit?
    self.match?(/\A\d\z/)
  end
end

Better/Alternative solution from Codewars

class String
  def digit?
    /\A\d\z/ === self
  end
end