{"id":23213230,"url":"https://github.com/siman-man/tspec","last_synced_at":"2025-08-19T05:32:55.348Z","repository":{"id":56897133,"uuid":"81825797","full_name":"siman-man/tspec","owner":"siman-man","description":"TSpec add simple type check of method into Ruby.","archived":false,"fork":false,"pushed_at":"2018-03-08T15:26:35.000Z","size":45,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-30T03:38:17.656Z","etag":null,"topics":["gem","ruby"],"latest_commit_sha":null,"homepage":"https://github.com/siman-man/tspec","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/siman-man.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-13T13:04:01.000Z","updated_at":"2017-02-16T01:58:55.000Z","dependencies_parsed_at":"2022-08-20T17:40:30.488Z","dependency_job_id":null,"html_url":"https://github.com/siman-man/tspec","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siman-man%2Ftspec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siman-man%2Ftspec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siman-man%2Ftspec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siman-man%2Ftspec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/siman-man","download_url":"https://codeload.github.com/siman-man/tspec/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230326794,"owners_count":18209050,"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":["gem","ruby"],"created_at":"2024-12-18T19:15:56.591Z","updated_at":"2024-12-18T19:15:57.417Z","avatar_url":"https://github.com/siman-man.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TSpec\n\n[![Build Status](https://travis-ci.org/siman-man/tspec.svg?branch=master)](https://travis-ci.org/siman-man/tspec)\n\nTSpec adds a method of simple type check to Ruby.\n\n:construction: **Recommended for use only in hobby programming. Do not use this in production apps.** :construction:\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'tspec'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it by yourself:\n\n    $ gem install tspec\n\n## Usage\n\nTSpec can use `#receive` and `#return` method.\n\n\n### receive\n\n`receive` defines the type of method arguments.\n\n```ruby\nrequire 'tspec'\n\ndef echo(str)\n  puts str\nend.receive(str: String)\n\necho('hello world') #=\u003e ok\necho(123)           #=\u003e TSpec::ArgumentTypeError\n```\n\nYou can specify multiple type, too.\n\n```ruby\nrequire 'tspec'\n\ndef echo(val)\n  puts val\nend.receive(val: [String, Float])\n\necho('hello')  #=\u003e ok\necho(3.14)     #=\u003e ok\necho(123)      #=\u003e TSpec::ArgumentTypeError\n```\n\nIf single method argument is given, you can skip keyword.\n\n```ruby\nrequire 'tspec'\n\ndef join_array(arr)\n  arr.join(' ')\nend.receive([String])\n\nputs join_array(%w(hello world)) #=\u003e ok\nputs join_array([1,2,3])         #=\u003e TSpec::ArgumentTypeError\n```\n\nYou can specify Array content type, although it may seem strange.\n\n```ruby\nrequire 'tspec'\n\ndef receive_string_array(arr)\n  arr.join\nend.receive(arr: [[String]])\n\nputs receive_string_array(['hello', 'world']) #=\u003e ok\nputs receive_string_array([:hello, :world])   #=\u003e TSpec::ArgumentTypeError\n```\n\n\n### return\n\n`return` defines the type of method return value.\n\n```ruby\nrequire 'tspec'\n\ndef message\n  'hello world'\nend.return(String)\n\ndef dummy_message\n  'hello world'\nend.return(Symbol)\n\nputs message        #=\u003e ok\nputs dummy_message  #=\u003e TSpec::ReturnValueTypeError\n```\n\nYou can specify multiple return value, too.\n\n```ruby\nrequire 'tspec'\n\ndef random_val\n  [1.0, '1', :hello].sample\nend.return(Float, String, Symbol)\n\n10.times do\n  v = random_val\nend\n```\n\nAlso, you can specify Array content type.\n\n```ruby\nrequire 'tspec'\n\ndef message_list\n  %w(hello ruby world)\nend.return([String])\n\np message_list\n```\n\n## Example\n\nCombination of `receive` and `return` method.\n\n```ruby\nrequire 'tspec'\n\ndef string2symbol(str)\n  str.to_sym\nend.receive(str: String).return(Symbol)\n\np string2symbol('hello')  #=\u003e :hello\np string2symbol(123)      #=\u003e TSpec::ArgumentTypeError\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/siman-man/tspec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n\n## License\n\nThe gem is available under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsiman-man%2Ftspec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsiman-man%2Ftspec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsiman-man%2Ftspec/lists"}