这是 Svelte 组件的片段:
<script>
let radius = 10;
$: area = Math.PI * radius ** 2;
// ...
</script>
Run Code Online (Sandbox Code Playgroud)
有人可以解释变量$:之前的目的是area什么吗?提前致谢。
Ruby 安全导航操作符 ( &.) 是否在其接收器为 时评估其参数nil?
例如:
logger&.log("Something important happened...")
Run Code Online (Sandbox Code Playgroud)
"Something important happened..."字符串是在这里求值的吗?提前致谢。
我的代码库中有如下代码:
logger&.log("Something important happened...")
Run Code Online (Sandbox Code Playgroud)
我的主要目标是if verbose在我调用该log方法时消除重复检查,因为很容易忘记它,并且您根本不会收到有关误用的通知。
我已经if verbose在log方法实现中移动了检查。
logger.log("Something important happened. (#{Time.current})") if verbose
Run Code Online (Sandbox Code Playgroud)
这种方法简化了我的代码,因为我已经解决了我的主要问题 -if verbose每次调用该log方法时我都不需要记住放置,
但我收到了另一个问题。
"Something important..."字符串总是被评估,无论verbose是true还是false。
因此,我彻底改变了解决方案:
logger返回nil时verbose是false。log调用前使用。class …Run Code Online (Sandbox Code Playgroud) 题
0当只发现警告时,是否可以告诉 Rubocop作为退出代码返回?
先决条件
我正在使用以下命令在 Travis CI 上运行 Rubocop:
bundle exec rubocop
Run Code Online (Sandbox Code Playgroud)
我有一个配置为警告的警察rubocop.yml:
Style/Documentation:
Severity: warning
Run Code Online (Sandbox Code Playgroud)
问题
Travis CI 仅当其退出代码等于 时才将命令视为成功的命令0。
当 Rubocop0没有发现任何违规行为时,它会作为退出代码返回,
但当它发现至少一项罪行时,
1无论此攻击是错误还是警告,它都会作为退出代码返回。
因此,当 Rubocop 仅发现警告时,Travis CI 构建失败。
因此,是否可以0在仅发现警告时告诉 Rubocop作为退出代码返回?
提前致谢。
笔记
请不要建议禁用警察。
我正在使用以下方法检查退出代码:
$ bundle exec rubocop
// ...
14 files inspected, 8 offenses detected
$ echo "$?"
1
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用GitHub CLI自动化GitHub的拉取请求创建过程的拉取请求创建过程。
\n我目前正在使用以下脚本,它的作用就像一个魅力:
\n(\n # Parentheses are used here to avoid the exposure of temporal variables to the outer scope.\n # Tested on macOS bash only.\n \n cd ~/Projects/pet_projects/basic_temperature\n \n # Pushes the release branch to the remote repository.\n git push origin release_nemo\n\n # Logs in to GitHub CLI using pre-generated access token.\n # https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token\n gh auth login --with-token < ~/Projects/pet_projects/.github_cli_access_token\n \n# Sets HEREDOC to PR_TITLE variable.\n# Indentation is avoided here intentionally.\n# https://stackoverflow.com/a/1655389/12201472\nread -r -d …Run Code Online (Sandbox Code Playgroud)