{"id":15523787,"url":"https://github.com/fntz/ov","last_synced_at":"2026-04-09T05:32:17.550Z","repository":{"id":11131210,"uuid":"13493967","full_name":"fntz/ov","owner":"fntz","description":"Create multimethods in Ruby","archived":false,"fork":false,"pushed_at":"2020-03-21T10:19:37.000Z","size":57,"stargazers_count":42,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-11-18T06:23:22.660Z","etag":null,"topics":["multimethods","ruby"],"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/fntz.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-10-11T08:42:07.000Z","updated_at":"2022-07-05T10:35:22.000Z","dependencies_parsed_at":"2022-08-28T19:51:28.977Z","dependency_job_id":null,"html_url":"https://github.com/fntz/ov","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fntz/ov","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fntz%2Fov","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fntz%2Fov/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fntz%2Fov/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fntz%2Fov/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fntz","download_url":"https://codeload.github.com/fntz/ov/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fntz%2Fov/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31587808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"online","status_checked_at":"2026-04-09T02:00:06.848Z","response_time":112,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["multimethods","ruby"],"created_at":"2024-10-02T10:46:57.889Z","updated_at":"2026-04-09T05:32:17.523Z","avatar_url":"https://github.com/fntz.png","language":"Ruby","readme":"# Ov\n\nCreate multimethods in Ruby\n\n## Installation\n\nAdd this line to Gemfile:\n\n    gem 'ov'\n\nExecute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install ov\n\n\n## A few examples:\n\n```ruby\nrequire 'ov'\n\n# ====== Define methods\n\nclass Foo\n  include Ov\n\n  let :foo, String do |str|\n    # some code \n  end\nend\n\nfoo = Foo.new\nfoo.foo(\"foo\") # =\u003e ok\nfoo.foo(123) # =\u003e Method `foo` in `#\u003cFoo:0x007fe423c19dc8\u003e` class with types `Fixnum` not implemented. (Ov::NotImplementError)   \n  \n# ====== Custom Equality for Ruby Types\n\n\nclass String\n  include Ov\n  let :is_equal, String do |str|\n    self == str \n  end \n\n  let :is_equal, Any do |other|\n    raise TypeError.new(\"Only for string\") \n  end\nend\n\nstr = \"foo\"\n\np str == 123            # false, but this different types\np str.is_equal(\"bar\")   # false\np str.is_equal(\"foo\")   # true\np str.is_equal(123)     # TypeError\n\n\n# ====== Use Ov::Ext for matching\n\nrequire 'kleisli'\n\ninclude Ov::Ext\n\nmatch(Try{1/0}) {\n  try(Kleisli::Try::Success) { puts \"ok\" }\n  try(Kleisli::Try::Failure) { puts \"error\" }  \n}\n\nresult = match(Net::HTTP.get_response(URI(\"http://google.com\"))) do\n  try(Net::HTTPOK) {|r| r.header }\n  try(Net::HTTPMovedPermanently) {|r| r.header }\n  otherwise { \"error\" }\nend\n\nputs result\n\n```\n\n\n\n\n## Usage\n\nFirstly include `Ov` in your class\n\n```ruby \nclass MyClass \n  include Ov \nend\n```\n\nAfter: define method with types:\n\n```ruby\nclass MyClass\n  include Ov\n  \n  #with Fixnum type \n  let :cool_method, Fixnum do |num|\n    num * 100\n  end \n  \n  #with String type\n  let :cool_method, String do |str|\n    str \u003c\u003c \"!\"\n  end \nend\n\n#And now\nmy_class = MyClass.new\nmy_class.cool_method(3)     # =\u003e 300\nmy_class.cool_method(\"foo\") # =\u003e foo! \n```\n\nClass Methods\n--------------\n\n```ruby\nclass MyClass\n  self \u003c\u003c class\n    let :cool_method, Fixnum do |f|\n      f + 1\n    end\n    let :cool_method, String do |s|\n      \"{s}\"\n    end\n  end\nend \n\n\nMyClass.cool_method(1)      #=\u003e 2\nMyClass.cool_method(\"test\") #=\u003e \"test\"\n```\n\n\nAny Type\n----------\n\n```ruby\nclass MyClass \n  include Ov\n  let :cool_method, Any do |any|\n    any\n  end \nend\n\nmy_class = MyClass.new\nmy_class.cool_method(1)     =\u003e 1 \nmy_class.cool_method(\"foo\") =\u003e \"foo\"\n```\n\n\nRedefine methods\n\n```ruby\nclass A \n  def test(str)\n    p \"A#test\" \n  end\nend\n\nclass B \u003c A \n  include Ov\n  let :test, Fixnum do |num|\n    p \"only for fixnum\"\n  end\nend \n\nb = B.new\nb.test(\"asd\") # =\u003e A#test\nb.test(123)   # =\u003e only for fixnum\n\n```\n\nCall method:\n\n```ruby\n\nclass A \n  include Ov\n\n  let :test, Fixnum do |num|\n    test(\"#{num}\") # call with string argument\n  end\n  \n  let :test, String do |str|\n    p str\n  end  \nend\n\na = A.new\na.test(123) # =\u003e \"123\"\n\n```\n\n\nWork with blocks\n\n```ruby\nclass MyClass\n  include Ov\n  let :my_method, Fixnum do |num, block| # instead of |num, \u0026block|\n    p num\n    block.call\n  end\nend\n\nMyClass.new.my_method(1) do \n  p \"123\"\nend\n # =\u003e 1\n # =\u003e 123\n```\n\nExamples\n--------\nsee [link](https://github.com/fntz/ov/blob/master/samples)\n\n## TODO\n\n1. work with symbol method names: `+, -, *, etc` \n2. some ideas\n\n```ruby\n# multiple arguments\nlet :test, Integer, [String] # signature: Integer, and others must be String\n\nlet :test, Multiple #any types\n\nlet :test, :foo # Type must have :foo method\n\nlet :test, Or[Integer, String] # work for String or Integer\n\n```\n\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","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffntz%2Fov","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffntz%2Fov","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffntz%2Fov/lists"}