What is the supported hash syntax for the default task in a Rakefile with Ruby v >= 1.9?
Asked Answered
N

1

2

In this Rakefile I want to set my default task to :test.

task :default => :test

Rubocop has now entered the scene and states

Style/HashSyntax: Use the new Ruby 1.9 hash syntax.

Great. I don't have much Ruby background, but I do know that the general hash syntax is meant to assign values and make it easy to get them later.

I honestly have no idea how to communicate this, where you have some task and there is a 'magic' default instance and I want to assign :test

I have tried a few permutations but none seem to work. I obviously don't come from the same planet.

Noyade answered 1/5, 2019 at 0:1 Comment(4)
"none seem to work" is not a precise enough error description for us to help you. What doesn't work? How doesn't it work? What trouble do you have with your code? Do you get an error message? What is the error message? Is the result you are getting not the result you are expecting? What result do you expect and why, what is the result you are getting and how do the two differ? Is the behavior you are observing not the desired behavior? What is the desired behavior and why, what is the observed behavior, and in what way do they differ?Adopted
What does it mean that they don't "seem" to work? Do they work or do they not work?Adopted
Egads. The answer is below. Well...it 'seems' to be at least.Noyade
Related: https://mcmap.net/q/517153/-alias-of-task-name-in-rake/4722345Anton
S
6

Rubocop is suggesting this:

task default: :test

It may look a bit strange at first but you get used to it.

Rubocop also needs to remember that Ruby 1.9 shipped twelve years ago in 2007. It's not "new". Support for it was cut in 2015. Shows how long Rubocop has been fighting to make Ruby code better.

Stouffer answered 1/5, 2019 at 0:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.