Override Symbol#to_sym to raise error on redundant calls#209
Closed
stefan-burke wants to merge 1 commit intomainfrom
Closed
Override Symbol#to_sym to raise error on redundant calls#209stefan-burke wants to merge 1 commit intomainfrom
stefan-burke wants to merge 1 commit intomainfrom
Conversation
This change overrides the Symbol#to_sym method to raise an ArgumentError when called on a Symbol instance. This helps catch redundant to_sym calls in the codebase, as calling to_sym on a Symbol is unnecessary and likely a mistake. The original to_sym method is aliased but not used to enforce this behavior. Additionally, comprehensive specs were added to verify that calling to_sym on a Symbol raises the error with the correct message, while calls on Strings and other objects that respond to to_sym continue to work normally. Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Symbol#to_symmethod to raise anArgumentErrorwhen called on a Symbolto_symon Symbol objects in the codebaseto_symstill works normally on Strings and other objectsChanges
Core Functionality
symbol_to_sym_override.rbthat:to_symmethodto_symon Symbol to raise an error with a descriptive messageTests
symbol_to_sym_override_spec.rbcovering:to_symis called on a Symbolto_symon Strings and other objects like integers and nilTest plan
to_symon a Symbol raises the expectedArgumentErrorto_symon String returns the correct Symbolto_symbehave as expected🌿 Generated by Terry
ℹ️ Tag @terragon-labs to ask questions and address PR feedback
📎 Task: https://www.terragonlabs.com/task/b20e9258-519c-4e25-bb13-a711531ff3ee