{"id":20240266,"url":"https://github.com/dwbutler/numeric","last_synced_at":"2025-07-26T04:04:49.924Z","repository":{"id":10561561,"uuid":"12764056","full_name":"dwbutler/numeric","owner":"dwbutler","description":"Adds numeric checking to Ruby","archived":false,"fork":false,"pushed_at":"2013-12-26T04:35:17.000Z","size":124,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-03-14T23:21:01.957Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dwbutler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-09-11T18:27:47.000Z","updated_at":"2013-12-26T04:35:18.000Z","dependencies_parsed_at":"2022-09-10T08:22:55.528Z","dependency_job_id":null,"html_url":"https://github.com/dwbutler/numeric","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwbutler%2Fnumeric","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwbutler%2Fnumeric/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwbutler%2Fnumeric/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwbutler%2Fnumeric/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dwbutler","download_url":"https://codeload.github.com/dwbutler/numeric/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241686832,"owners_count":20003112,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T08:44:54.306Z","updated_at":"2025-03-03T15:13:41.405Z","avatar_url":"https://github.com/dwbutler.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Numeric [![Build Status](https://travis-ci.org/dwbutler/numeric.png)](https://travis-ci.org/dwbutler/numeric)\n\nChecking if a given value is \"numeric\" is a common problem. How can we do in this Ruby?\nThere are many problematic ways, such as converting to an integer or float or using a regex:\n\n```ruby\n\"String\".to_i\n# =\u003e 0\n\nnil.to_f\n# =\u003e 0.0\n\n:'0'.to_i\n# NoMethodError: undefined method `to_i' for :\"0\":Symbol\n\n\"1e5\" =~ /^\\d*$/\n =\u003e nil\n```\n\nThis gem defines a simple (and correct) `#numeric?` method on all Ruby objects.\nThe rules are simple:\n\n * All descendants of `Numeric` are numeric.\n * All strings or symbols that can be converted with `Complex()` are numeric.\n * All other objects are not numeric.\n\nIf you want to get more specific, the following methods are also defined:\n\n * `#integer?`\n * `#float?`\n * `#decimal?`\n * `#rational?`\n * `#complex?`\n\nNote that for these more specific methods, a string that can be converted to\na `Float` (such as '1') will return `true` for `#float?`. An instance of a different\nNumeric class (such as 1, Integer) will return `false` for `#float?`.\n\n## Compatibility\n\nThe gem is tested to work in MRI Ruby 1.9 - 2.0, and JRuby (1.9 mode).\nAll other Rubies are too lax in what their `Numeric` classes accept, which prevents\nthis gem from working completely.\n\nMRI 2.0.0's `BigDecimal` class is also too lax in what it accepts, so `'a'.decimal?` will\nunfortunately return `true`.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'numeric'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install numeric\n\n## Usage\n\n```ruby\nrequire 'numeric'\n\n3.numeric?\n# =\u003e true\n\n'1'.numeric?\n# =\u003e true\n\n'3e10'.numeric?\n# =\u003e true\n\n:'0'.numeric?\n# =\u003e true\n\n'abc123'.numeric?\n# =\u003e false\n\n{}.numeric?\n# =\u003e false\n```\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwbutler%2Fnumeric","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdwbutler%2Fnumeric","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwbutler%2Fnumeric/lists"}