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
cover
andinclude
are similar, butcover
only 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
delegate
method is similar toshow
but uses symbols instead of strings -
Using
eval
or 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
send
method can be fast, but RuboCop may yell at you - Capturing groups in regular expressions can lead to unexpected behavior
-
Using
rescue
andrescue_not_implemented_error
can lead to unexpected behavior -
Using Ruby’s built-in methods like
upcase
anddowncase
can be faster -
Using
include
andcover
methods can be similar, butcover
only checks the beginning and end of the range