- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: ruby-best-practices/no-explicit-rb-to-require
Language: Ruby
Severity: Notice
Category: Best Practices
The rule “Omit the rb file extension in a require” is a coding convention in Ruby programming. It is designed to enforce the best practice of omitting the “.rb” extension when using the require
or require_relative
methods to include another Ruby file. This is because Ruby’s require
method automatically searches for the “.rb” extension, and including it is redundant.
This rule is important because it promotes cleaner and more readable code. Writing the extension in a require
statement is unnecessary and can lead to confusion. In addition, adhering to this rule can prevent potential issues with file loading, as Ruby might interpret a require with an explicit “.rb” extension differently.
To avoid violating this rule, omit the “.rb” extension when using require
or require_relative
. For example, instead of writing require 'foo.rb'
, write require 'foo'
. For relative paths, instead of require_relative '../bar.rb'
, use require_relative '../bar'
. This will ensure your code is clean, readable, and adheres to Ruby’s best practices.
require 'foo.rb'
require_relative '../bar.rb'
require 'foo'
require 'bar.so'
require_relative '../baz'
require_relative '../qux.so'
|
|
For more information, please read the Code Analysis documentation
Identify code vulnerabilities directly in yourVS Code editor
Identify code vulnerabilities directly inJetBrains products