Rails - content_tagの使い方
content_tagメモ
before
<div class="alert alert-<%= message_type %>"><%= message %></div>
after
<%= content_tag(:div, message, class: "alert alert-#{message_type}") %>
Rails - byebug gemを導入してdebuggerでデバッグする
debuggerの使い方メモ (RubyMineでいいじゃん感)
Rails - テーブルにカラムを追加する
rails g migration add_<カラム名>_to_<テーブル名> <カラム名>:<カラムの型>
具体例
rails g migration add_password_digest_to_users password_digest:string
Ruby - Refinementsとは
Refinementsとは、Rubyにおけるオープンクラスのスコープを特定の範囲に限定するもの。
具体的に見ていくと、下記のようなオープンクラスを用いた場合、その影響範囲はアプリケーション全体となり、予期せぬところでコードを破壊するなどの危険性があった。
class String def to_alphanumeric gsub(/[^\w\s]/, '') end end
そのため、Refinementsによりオープンクラスの効果範囲を特定のモジュールだけに限定できるようにした。下記のように、refine クラス名 do ... end の形式で宣言し、モジュール内でusingすることでオープンクラスの効果を限定することができる。
module StringExtentions refine String do def to_alphanumeric gsub(/[^\w\s]/, '') end end end module SomeModule using StringExtentions "#3, the *Magic, Number*?".to_alphanumeric # => "3 the Magic Number" end
【オブジェクト指向】SOLID原則について
ググったけどリスコフの置換原則などに関して分かりやすい良記事が見つからなかった。
TODO(後で読む)
https://www.amazon.co.jp/dp/4797347783
アジャイルソフトウェア開発の奥義 第2版 オブジェクト指向開発の神髄と匠の技