We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
RailsConf 2024 - This or that? Similar methods & classes in Ruby && Rails by Andy Andrea
Discover the pitfalls and best practices for using Ruby's delegation methods, uncovering common mistakes and unexpected behavior that can affect your code's performance and security.
Using Ruby’s Delegation Methods
- Ruby’s delegation methods can lead to subtle bugs and affect garbage collection
-
Methods like
coverandincludeare similar, butcoveronly checks the beginning and end of the range - Using a regular expression with capture groups can lead to unexpected behavior
-
The
match?method can be slow, especially when using regular expressions - Delegating to instance variables or hardcoded strings can lead to unexpected behavior
- Monkey patching can be used to modify classes, but can also lead to unexpected behavior
-
The
delegatemethod is similar toshowbut uses symbols instead of strings -
Using
evalor class_eval can open up classes, but can also lead to security risks - Delegating to methods can lead to unexpected behavior and side effects
-
Using
sendmethod can be fast, but RuboCop may yell at you - Capturing groups in regular expressions can lead to unexpected behavior
-
Using
rescueandrescue_not_implemented_errorcan lead to unexpected behavior -
Using Ruby’s built-in methods like
upcaseanddowncasecan be faster -
Using
includeandcovermethods can be similar, butcoveronly checks the beginning and end of the range