- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: ruby-best-practices/global-stdout
Language: Ruby
Severity: Notice
Category: Best Practices
The rule “Avoid standard constants” is important in Ruby development as it encourages the use of global variables over standard constants. In Ruby, standard constants like STDOUT
and STDERR
are not as flexible as their global counterparts $stdout
and $stderr
.
The main reason for avoiding standard constants is that they are not interchangeable in the same way that global variables are. This means they are less suited to situations where you might need to redirect output or error streams. For instance, in testing scenarios, you might want to redirect $stdout
or $stderr
to a different output stream.
Fortunately, Ruby provides an easy way to avoid this issue. Instead of using standard constants, you should use global variables. For example, replace STDOUT
with $stdout
and STDERR
with $stderr
. This allows for greater flexibility in your code and makes it more adaptable to different situations.
STDOUT.puts('foo')
hash = { out: STDOUT, key: value }
def m(out = STDOUT)
out.puts('foo')
end
$stdout.puts('foo')
hash = { out: $stdout, key: value }
def m(out = $stdout)
out.puts('foo')
end
|
|
For more information, please read the Code Analysis documentation
Identify code vulnerabilities directly in yourVS Code editor
Identify code vulnerabilities directly inJetBrains products