Skip to content

Instantly share code, notes, and snippets.

View JunichiIto's full-sized avatar

Junichi Ito JunichiIto

View GitHub Profile
@JunichiIto
JunichiIto / tokyogirlsrb-vol1-video.md
Last active February 10, 2019 03:31
録画協力枠について (TokyoGirls.rb Meetup vol.1)

録画協力枠について (TokyoGirls.rb Meetup vol.1)

録画協力枠とは?

録画協力枠とは、当日の講演の様子を録画して動画ファイルを共有してもらえる方が申込み可能な参加枠です。

運営チームでは登壇の撮影を行う余裕がないため、参加者の方にお手伝いいただきたいです🙏

何のために録画するの?

ppメソッドでJSON.parse(response.body)の中身を確認してみました。

require 'rails_helper'

describe 'Projects API', type: :request do
  it 'loads a project' do
    user = FactoryBot.create(:user)
    FactoryBot.create(:project, name: "Sample Project")
    FactoryBot.create(:project, name: "Second Sample Project", owner: user)
RSpec.describe do
example do
dbl = double
allow(dbl).to receive(:x) do |*args|
case args.size
when 1 then 'foo'
when 2 then 'bar'
end
end
expect(dbl.x(10)).to eq 'foo'
@JunichiIto
JunichiIto / regex.txt
Last active October 28, 2018 01:15
Regex test for ^ and $.
$ irb
irb(main):001:0> "".match? /^/
=> true
irb(main):002:0> "".match? /$/
=> true
irb(main):003:0> "".match? /^$/
=> true
irb(main):017:0> code = <<RUBY
irb(main):018:0" [1, 2, 3].each do
@JunichiIto
JunichiIto / dvd.applescript
Last active October 21, 2018 01:32
Use VLC to open VIDEO_TS folder instead of DVD Player app for macOS Mojave
tell application "VLC"
activate
open file "Users:your-name:Documents:some-dvd:VIDEO_TS"
play
end tell

こちらの検証結果

irbで実行したところ、本書の記述通りになりました(Mac、Windowsとも)

screen shot 2018-07-27 at 3 51 01

本書のサンプルコードは特に断りがない限り、irb上での出力結果を載せています(1.6.1項参照)。

ファイルに保存して出力した場合

なんとなくの予想なのですが、ぬうさんは次のようなコードをファイルに保存して実行したのではないでしょうか?

  1. RubyMineを終了する
  2. 対象プロジェクトのディレクトリをリネームする(例: mv awesome-project awesome-project.old
  3. GitHubからプロジェクトを再度ローカルにcloneする
  4. コマンドラインからbundle installする
  5. RubyMineを起動する
  6. 上記3でcloneしたプロジェクトを開く
@JunichiIto
JunichiIto / answer-2018.03.29.md
Last active March 29, 2018 12:36
Question and answer about プロを目指す人のためのRuby入門

Q.

p250で、クラスメソッドをprivateにしたい場合とありますが、privateメソッドは「レシーバを指定して呼び出すことができない」とあるので不思議です。 User.hello のUserはレシーバとは呼ばないのかということです。

https://twitter.com/maehrm/status/979326471075278848

A.

いいえ、Userはレシーバです。なので、クラスメソッドのhelloがprivateメソッドだった場合は、User.helloのようにレシーバを指定して呼び出すとエラーになります。

# example(it)内でローカル変数を宣言する
describe 'convert_hash_syntax' do
it '=>が:に置き換わる' do
old_syntax = <<~TEXT
{
:name => 'Alice',
:age => 20,
:gender => :female
}
TEXT
@JunichiIto
JunichiIto / benchmark.rb
Created December 14, 2017 04:39
How slow Ruby exception is?
# Based on http://blog.honeybadger.io/benchmarking-exceptions-in-ruby-yep-theyre-slow/
require 'benchmark/ips'
def find_by
nil
end
def find_by!
raise 'Not found'
end