Skip to content

Instantly share code, notes, and snippets.

View r7kamura's full-sized avatar

Ryo Nakamura r7kamura

View GitHub Profile

Install rbenv on Mac OS X

homebrewで依存ライブラリを入れた後、homebrewでrbenvとruby-buildを入れる。

Requirements

rbenvとruby-buildを入れるために、以下のライブラリが必要。 過去に既に古いバージョンのものが入っていた場合は、brew linkしたり、brew link --forceする必要があるかもしれない。 自分の場合は、opensslとreadlineがそうだった。

  • libyaml
  • openssl
@r7kamura
r7kamura / factory_bot_factories_spec.rb
Last active November 13, 2020 05:33
Example to lint FactoryBot factories with RSpec.
require 'rails_helper'
RSpec.describe 'FactoryBot factory' do
FactoryBot.factories.each do |factory|
describe factory.name.inspect do
it 'creates valid record' do
expect { FactoryBot::Linter.new([factory]).lint! }.not_to raise_error
end
end
end
# frozen_string_literal: true
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'activerecord', '6.0.3.4'
gem 'sqlite3'
end
@r7kamura
r7kamura / i18n_symbol_reference_feature_example.rb
Last active November 5, 2020 07:45
An example of how to reuse other values by symbol translation key value on i18n gem.
require 'i18n'
require 'yaml'
I18n.backend.store_translations(
:en,
YAML.load(<<-YAML)
activerecord:
attributes:
user:
status:
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'activerecord', '6.0.0'
gem 'sqlite3'
end
require 'active_record'
@r7kamura
r7kamura / rename_factories_to_plurals.rb
Last active October 28, 2020 17:06
Rename FactoryBot files from singular to plural.
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'activesupport'
end
require 'active_support/inflector'
require 'pathname'
@r7kamura
r7kamura / space_probe.rb
Last active September 25, 2020 19:13
A Ruby script to print cop names which include "space".
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'activesupport'
gem 'rubocop', '0.84.0'
gem 'rubocop-performance', '1.6.0'
gem 'rubocop-rails', '2.5.2'
module Kernel
alias_method :original_require, :require
def require(path)
time = ::Time.now
original_require(path).tap do
puts "%3.6f\t#{path}" % (Time.now - time)
end
end
end
shared_examples "foo" do
# ここで "foo" を参照したいのですが、何か方法はありませんか?
end
class MyError < StandardError
def initialize(**options)
p options
end
end
raise MyError, foo: :bar