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.

Key takeaways

Using Ruby’s Delegation Methods

  • Ruby’s delegation methods can lead to subtle bugs and affect garbage collection
  • Methods like cover and include are similar, but cover 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 to show 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 and rescue_not_implemented_error can lead to unexpected behavior
  • Using Ruby’s built-in methods like upcase and downcase can be faster
  • Using include and cover methods can be similar, but cover only checks the beginning and end of the range