Instance methods (17) as_json compact_blank (>= v6.1.3.1) each_with_object (<= v3.2.13) exclude? excluding (>= v6.0.0) group_by (<= v3.2.13) including (>= v6.0.0) index_by index_with (>= v6.0.0) many? none? (<= v2.3.8) _original_sum_with_required... (<= v5.1.7) pick (>= v6.1.3.1) pluck sum to_json (<= v2.3.2) without = private = protected Convert an enumerable to a hash. people.index_by(&:login) #
bashなどのshellでシングルクオートで囲まれた中でシングルクオートをエスケープする方法は残念ながらない。たとえば、 ssh host02 'ssh host03 \'ls -l\' 'みたいなことはできない。 しかし、クオートを一旦閉じてから、シングルクオートをバックスラッシュでエスケープして入力しその後クオートを再開することで、そのようなことが実現できるようだ。 ssh host02 'ssh host03 '\''ls -l'\'' 'すなわち、\'ではなく、'\''ということだ。 おまけ: シングルクオートを'\''に置換するワンライナー ruby -pe '$_.gsub!(/'\''/, %q('"'\\\\\\\\''"'))'
mysql> desc user_data; +---------+-----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------+-----------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | user_id | int(11) | YES | | NULL | | | data | int(11) | YES | | NULL | | | detail | char(255) | YES | | NULL | | +---------+-----------+------+----
Documentation There is extensive documentation on Ransack, which is a Docusaurus project and run as a GitHub Pages site. Issues tracker Before filing an issue, please read the Contributing Guide. File an issue if a bug is caused by Ransack, is new (has not already been reported), and can be reproduced from the information you provide. Please consider adding a branch with a failing spec describing
あるテーブルに対して複数のレコードを同時に登録したいことがあります。 このときに登録する数だけINSERTを発行するのはあまり効率がよくありません。 そこでBULK INSERTと言われる単発のSQLで一括登録する方法がよく使われます。 BULK INSERTとは 単純なbooksというテーブルを使い、BULK INSERTはどういうものか確認する。 CREATE TABLE `books` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAU
Rubyスクリプトから別のRubyスクリプトを呼び出したい時がある. そういう場合, msg=`hoge.rb` とすると,hoge.rbが標準出力へ出力した文字列すべてを変数msgで受け取ることが出来る. 1行ずつ受け取って処理したい場合は, IO.popen("hoge.rb") do |pipe| pipe.each do | line | print line end end という感じにすれば,1行ずつとって表示することが出来る. しかし,デフォルトだと,Rubyスクリプトの標準出力はバッファリングされるため,hoge.rbの処理に時間がかかる場合,長い時間立った後に,まとめてhoge.rbの出力をどかっと渡されるようになる. (受け取ったプログラムは,それを1行ずつ処理することはできるけれど) これは標準出力がバッファリングされているのが原因なので,バッファリングしないようにす
Active Support Concern A typical module looks like this: module M def self.included(base) base.extend ClassMethods base.class_eval do scope :disabled, -> { where(disabled: true) } end end module ClassMethods ... end end By using ActiveSupport::Concern the above module could instead be written as: require "active_support/concern" module M extend ActiveSupport::Concern included do scope :disabled, -
it, specify, exampleそれぞれの先頭にxをつけるだけで、Pendingになる。 describe Foo do xit { 1.should eq 1 } xspecify { 1.should eq 1 } xexample { 1.should eq 1 } end Pending: Foo # Temporarily disabled with xit # ./spec/models/foo_spec.rb:4 Foo # Temporarily disabled with xexample # ./spec/models/foo_spec.rb:6 Foo # Temporarily disabled with xspecify # ./spec/models/foo_spec.rb:5 Register as a new user and use Qiita m
自分の環境では、sortコマンドを実行する時にLC_ALL環境変数に'C'をセットするかしないかで、処理終了までの時間が著しく変わる。 # 約40万行のデータ > wc -l words 392126 words # 入っているのはUTF-8の日本語(IPA辞書を利用) > head words やぼったい やぼったし やぼったから やぼったかろ やぼったかっ # 普通のソート > time sort words > /dev/null real 0m37.158s user 0m37.098s sys 0m0.056s # LC_ALL=Cでのソート > time LC_ALL=C sort words > /dev/null real 0m0.293s user 0m0.284s sys 0m0.008s ロケールを考慮してソートするかどうかの違いだと思うが(LC_ALL=Cの場合は、
文字列検索にはgrepコマンドを使うのが一般的だ。 grepコマンドは正規表現による検索をサポートしており、正規表現で使用するメタ文字という特殊な文字(\、[、]、^、$、*、.など)を含む文字列を検索する際はメタ文字の前にバックスラッシュ(\)を付けなければならない。メタ文字が少数であれば問題ないが、数が多くなるとバックスラッシュでエスケープするのは面倒だ。そんなときは、正規表現をサポートしないgrepであるfgrepコマンドを使う。 例えば、「********」という文字を検索する場合、grepコマンドでは、
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く