Foo
.bar
.baz
Pry.commands.delete /\.(.*)/
doc = <<-'SONG'
Business men, they drink my wine
#{person} dig my earth
None will level on the line
Nobody offered his word
Hey, hey
SONG
You can switch Ruby version temporarily with rbenv local
But it'd need to be switched back after you're done. Specially for a single command it's kind of pain. In those cases, you can use RBENV_VERSION env variable.
RBENV_VERSION=2.6.3 ruby -v
This might be useful in a shell script or so.
All intermediate-level hashtables will be created automagically
def autovivifying_hash
Hash.new {|ht,k| ht[k] = autovivifying_hash}
end
response_builder = autovivifying_hash
response_builder['payment']['status'] = 'OK'
response_builder # => {"payment"=>{"status"=>"OK"}
Just open your user settings JSON file and use this option:
"editor.multiCursorModifier": "cmd",
Level up your bundler performance by running bundler tasks concurrently in jobs:
$ bundle config --global jobs 4
See more options on the bundler website.
FactoryBot.define do
factory :citizen_id_image, class: CitizenIdImagePresenter do
image_url { 'https://placehold.it/200x200' }
initialize_with { new(image_url: image_url) }
end
end
build(:citizen_id_image)
#=>
User 1 - 0..1 Laptop
a/m/laptop.rb belongs_to :user, optional: true ```
Generating a rails 6 app with ruby 2.6+ when you have bundler v2 installed creates unusable binstubs. If you are seeing this error You must use Bundler 2 or greater with this lockfile. you can remove the bundler that comes bundled with ruby 2.6 and rely on the manually installed v2 bundler.
If you are using rbenv you can use this command (adjust for your ruby version e.g. 2.6.{0, 1} etc), other installation systems will use different locations
rm -rf ~/.rbenv/versions/2.6.1/lib/ruby/2.6.0/bundler*
$ RUBYOPT=W0 ./bin/rspec spec/
...
$ RUBYOPT=W0 bundle exec rspec spec/
...
$ RUBYOPT=W0 rspec
...
$ RUBYOPT=W0 ...
...
$VERBOSE = nil
def suppress_warnings original_verbose = $VERBOSE $VERBOSE = nil yield ensure $VERBOSE = original_verbose end suppress_warnings do require 'some_gem_with_warnings' end
RSpec.configure do |config| config.warnings = false end
RSpec.configure do |config| config.deprecation_stream = File.open('log/rspec_deprecations.log', 'w') end
$VERBOSE = nil if ENV['SUPPRESS_WARNINGS'] == 'true'
$ git diff develop feature/one-signal --diff-filter=M --name-only -- *.rb | egrep -v 'db|config|spec' | xargs rubocop
#!/usr/bin/env ruby
require 'english'
require 'rubocop'
ADDED_OR_MODIFIED = /A|AM|^M/.freeze
changed_files = `git status --porcelain`.split(/\n/).
select { |file_name_with_status|
file_name_with_status =~ ADDED_OR_MODIFIED
}.
map { |file_name_with_status|
file_name_with_status.split(' ')[1]
}.
select { |file_name|
File.extname(file_name) == '.rb'
}.join(' ')
system("rubocop #{changed_files}") unless changed_files.empty?
exit $CHILD_STATUS.exitstatus
$ chmod +x .git/hooks/pre-commit
$ git commit -n -m "[hotfix] blah blah"