Skip to content

Improve Sitemap method-missing implementation#473

Merged
n-rodriguez merged 5 commits intokjvarga:masterfrom
jasonkarns:method-missing-proper
Mar 20, 2026
Merged

Improve Sitemap method-missing implementation#473
n-rodriguez merged 5 commits intokjvarga:masterfrom
jasonkarns:method-missing-proper

Conversation

@jasonkarns
Copy link
Copy Markdown

@jasonkarns jasonkarns commented Mar 6, 2026

Fix up the implementation of method-missing for the SitemapGenerator::Sitemap parent class.

method missing implementations should:

  • be private
  • delegate unknowns to its ancestors
  • override respond_to_missing?, not respond_to?

Also

  • improve the debug-ability of this class by giving it a name.
  • update the gemspec to properly report the required ruby version.
  • use proper __send__, not send
  • only delegate public methods so as to not break encapsulation and leak private methods

Fixes #472

@jasonkarns jasonkarns force-pushed the method-missing-proper branch from f2bd91b to b9f92e4 Compare March 9, 2026 14:56
@jasonkarns jasonkarns force-pushed the method-missing-proper branch 2 times, most recently from 7deb532 to 4d16352 Compare March 16, 2026 20:05
When the LinkSet doesn't respond to a particular method, method-missing
should defer to its ancestors.

Ideally, only public methods are delegated to LinkSet. (And it should
only be using `public_send`) But evidently it currently assumes
delegation of even private methods 😱 so preserve that behavior.

But as long as we're using private send, we should at least be using the
proper method: __send__
It is not user-friendly to have anonymous classes. They are hard to
debug.

So let's give the SitemapGenerator::Sitemap's class a name (Config)
@jasonkarns jasonkarns force-pushed the method-missing-proper branch from 4d16352 to c0f43bd Compare March 16, 2026 20:26
Sitemap = (Class.new do
def method_missing(*args, &block)
(@link_set ||= reset!).send(*args, &block)
Sitemap = (Config = Class.new do
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Giving the anonymous class a name here to enhance debug-ability. Looking at classes in the inheritance hierarchy without names is difficult to trace and understand.

Open to alternatives besides SitemapGenerator::Config, though.

@n-rodriguez n-rodriguez merged commit 7d30a9e into kjvarga:master Mar 20, 2026
77 checks passed
jasonkarns added a commit to jasonkarns/sitemap_generator that referenced this pull request Mar 21, 2026
* upstream/master:
  Enhance Rails railtie to respect existing rails configuration (kjvarga#478)
  Improve Sitemap method-missing implementation (kjvarga#473)
  Fix broken specs (kjvarga#476)
  Simplify rake task hierarchy (kjvarga#477)
  Fix AWS upload deprecation (kjvarga#464)
@jasonkarns jasonkarns deleted the method-missing-proper branch March 21, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

method-missing is not implemented correctly

2 participants