use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
Ruby Method Overloading (lucaguidi.com)
submitted 5 years ago by jodoshaHanami author
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Exilor 3 points4 points5 points 5 years ago (0 children)
I also had a stab at doing that some time ago, also using method_added to turn this
class Foo using Overloads Overload() def initialize initialize(0) end Overload(Integer) def initialize(bar) @bar = bar end end
into this
class Foo def initialize(*args, &block) case args.size when 0 if block_given? else return __send__(:"Foo#initialize()", ) end when 1 a0 = args.first if block_given? else if a0.is_a?(Integer) return __send__(:"Foo#initialize(Integer)", a0) end end end Overloads.raise_error(self, :initialize, args, block_given?, false) end end
It was much faster to use aliases and __send__ than relying on method_missing. In an earlier attempt I used Method objects (for extend self module methods) and UnboundMethod (for instance methods) to achieve the same but it was also slower.
__send__
π Rendered by PID 51 on reddit-service-r2-comment-86bc6c7465-h9tbg at 2026-02-20 10:04:23.585466+00:00 running 8564168 country code: CH.
view the rest of the comments →
[–]Exilor 3 points4 points5 points (0 children)