!Mac OS X-10.15.7!ruby-2.7.1p83
There is a slogan called Convention over Configuration. Configuration means setting, but it's nice to be able to set as many software operations as you like. However, in most cases, the defaults are used, and you don't have to find out where and what is, so everyone doesn't get lost. In that case, the convention is "don't leave the default" (which is translated as a convention, but I'm more familiar with the convention center, meaning a way in which something is usually done). ..
Ruby on Rails developed by David Heinemeier Hansson (DHH) is a thorough systemization of this. As a touch of CoC, I will introduce the rules of bin in the linux world and the feeling of scaffolding (scaffolding) that often starts with Rails.
Let's use it when it works. Set shebang and change it to executable.
It is very convenient if you devise a place to put it.
. # very local
There is the idea of tight binding. This is intended to keep the files you need as close to where you need them as possible. This will increase portability.
If you organize it by type such as exec or put it in ~ / bin etc., it will explode soon. local can be executed in the project required for local. In addition, you will be able to fix the choco choco without hesitation. I only use it here.
The more files there are, the longer it will take for the system to find them. So I set the path, but this is a kind of configuration that I do not want to do. But it can't be helped, so please remember.
bundler
Furthermore, it would be convenient if convenient things and common apps used in various situations could be used from various places. In such a case, let's use a gem.
You will be asked a few questions at first, but please answer with COC: "yes", MIT: "yes", TEST: "minitest". This will automatically generate the files needed to create the gem.
The rest is a little correction.
bundle manages backup with git by default. So you need to set it, but for now, remove it.
It doesn't work.
I wonder if it works with.
A little more,
I will fix the place where I was angry with. Let's comment out now.
In addition, lib / hogehoge.rb
cat lib/hello_rudy.rb
require "hello_rudy/version"
module HelloRudy
class Error < StandardError; end
# Your code goes here...
puts "Hello "+ARGV[0]
end
Then, if you can confirm that it works,
> rake install:local
hello_rudy 0.1.0 built to pkg/hello_rudy-0.1.0.gem.
hello_rudy (0.1.0) installed.
Then
> hello_rudy Rudy
Hello Rudy
It's working properly, right?
This does not include configuration. The gem does a good job of where to put it and how to read it. If you are interested, please check with gem env.
scaffolding
Take a look at how the command bundle is automatically created.
> tree
.
├── CODE_OF_CONDUCT.md
├── Gemfile
├── Gemfile.lock
├── LICENSE.txt
├── README.md
├── Rakefile
├── bin
│ ├── console
│ └── setup
├── exe
│ └── hello_rudy
├── hello_rudy.gemspec
├── lib
│ ├── hello_rudy
│ │ └── version.rb
│ └── hello_rudy.rb
├── pkg
│ └── hello_rudy-0.1.0.gem
└── spec
├── hello_rudy_spec.rb
└── spec_helper.rb
6 directories, 15 files
It is.
――Determine where and what to put.
This is the beginning of CoC. Notice that the name is also automatically generated. After that, correct according to the instructions. This is also TDD.