Ruby::Overload

Gem Version Build Status

Runtime method overloading behavior for Ruby from this blog post by @jodosha. Incorporates changes from ptolemybarnes/overlord, performance improvements from baweaver@, and other ideas from this tweet.

Disclaimer

The original author of this idea, Luca Guidi, does not recommend using this in production, but YOLO.

Usage

require 'ruby-overload'

class Foo
  include Ruby::Overload

  def call
    puts "foo"
  end

  def call(arg)
    puts "foo #{arg}"
  end
end

foo = Foo.new
foo.call # => "foo"
foo.call(23) # => "foo 23"

Contributing

You're encouraged to contribute to this gem. See CONTRIBUTING for details.

Copyright (c) 2020, Luca Guidi, Brandon Weaver, Daniel Doubrovkine and Contributors.

This project is licensed under the MIT License.

Similar Projects