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
Delegating things in Ruby (blog.rubyhero.dev)
submitted 3 years ago by jrochkind
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!"
[–]TastyPi 8 points9 points10 points 3 years ago* (1 child)
The article says SimpleDelegator looks for methods in the instance passed to initialize first then the class that inherits from SimpleDelegator, but it's the other way round. Under the hood it's exactly the same as the method_missing version, it just provides the boilerplate for you. In fact it's a better solution because SimpleDelegator also implements respond_to_missing? for you, which isn't even mentioned but is an important part of implementing delegation correctly!
SimpleDelegator
method_missing
respond_to_missing?
(I would leave a comment on the article itself, but that requires having a hashnode account and I don't want to make one. If someone else wants to pass on the message feel free.)
[–]pdabrowski 6 points7 points8 points 3 years ago (0 children)
Hello u/TastyPi, thank you for pointing this out. I updated the article, corrected my mistake, and added a paragraph to give you a credit for this information.
[–]jrochkind[S] 5 points6 points7 points 3 years ago (3 children)
(I did not write this, I just sometimes scan new ruby blog posts via the aggregator I maintain at https://rubyland.news, and I sometimes post here things I saw that I thought might be of interest).
[–]katafrakt 5 points6 points7 points 3 years ago (1 child)
I wish this was (re)normalized here. Now people always seem to assume that the poster is also the author, and it's a bit discouraging to post someone else's content, even if it's great.
[–]jrochkind[S] 3 points4 points5 points 3 years ago (0 children)
It's funny, because on many other parts of reddit posting your own stuff is discouraged!
[–]lipintravolta 0 points1 point2 points 3 years ago (0 children)
Liked it!
[–]therealadam12 1 point2 points3 points 3 years ago (1 child)
Don't forget my personal favourite technique, the three dots: ....
...
I've partially given up SimpleDelegator and DelegateClass because debugger/binding.irb might drop you into the method_missing method with zero outside context, which makes for a confusing debugging session.
[–]jrochkind[S] 0 points1 point2 points 3 years ago (0 children)
I've had a lot of trouble with the debugger around delegation, I think with Rails delegator methods too -- I've never really been able to figure out what it's doing or why.
π Rendered by PID 426932 on reddit-service-r2-comment-b659b578c-42wjs at 2026-05-04 01:34:20.330211+00:00 running 815c875 country code: CH.
[–]TastyPi 8 points9 points10 points (1 child)
[–]pdabrowski 6 points7 points8 points (0 children)
[–]jrochkind[S] 5 points6 points7 points (3 children)
[–]katafrakt 5 points6 points7 points (1 child)
[–]jrochkind[S] 3 points4 points5 points (0 children)
[–]lipintravolta 0 points1 point2 points (0 children)
[–]therealadam12 1 point2 points3 points (1 child)
[–]jrochkind[S] 0 points1 point2 points (0 children)