Rubyでその必要性は明らかだけれども名前が決まらずに承認されないメソッドというのがあって長く議論が続いているものに「単にselfを返すメソッド」というのがあるよ。 Feature #6373: public #self - ruby-trunk - Ruby Issue Tracking System ruby - Is there a short way to write {|x| x}? - Stack Overflow
New to Ruby and ROR and loving it each day, so here is my question since I have not idea how to google it (and I have tried :) ) we have method def foo(first_name, last_name, age, sex, is_plumber) # some code # error happens here logger.error "Method has failed, here are all method arguments #{SOMETHING}" end So what I am looking for way to get all arguments passed to method, without listing each
この記事は、Rubyを書くにあたって「いかにブロックを書かずにすませるか」を追求した、誰得な連載である。 だって、ブロックって汚いじゃん?仮引数の|x|とかキモイ。 Symbol#to_proc 基本中の基本。 instance method Symbol#to_proc 以下のようなArrayがあって、 irb(main):003:0> arr = [:user, :entry, :article, :comment, :category] => [:user, :entry, :article, :comment, :category] 各要素をto_sしたかったら、 irb(main):004:0> arr.map{|s| s.to_s} => ["user", "entry", "article", "comment", "category"] と書くかわりに、 irb(main)
ruby-talk の 381425 で 「どのメソッドが呼び出されているのか調べる方法を知りたい」 という内容の質問がありました。 私も知らなかったのですが、Method オブジェクトを使えば簡単に知ることができるそうです。 というわけで、メソッドがどこで定義されているのかを調べる方法を書いておきます。 メソッドを定義しているクラスまたはモジュールへの参照を取得する あるメソッドがどのクラス (またはモジュール) で定義されているかを知りたければ、そのメソッドに対応する Method オブジェクトを取得し、Method#owner メソッド を呼び出します。 それだけで、メソッドを定義しているクラス (またはモジュール) への参照を取得できます。 ちなみに、ある名前のメソッドに対応する Method オブジェクトを取得するには、Kernel#method メソッド を使用します。 'あい
Irb is one of the most commonly used standard ruby libraries, yet most don’t seem to know much about it. I’ve lost count of the number of blog posts that explain some irb “tricks” or “secret” config options. This is the first in a series that aims to make irb less magical and more accessible. First off, I’m assuming you know your way around irb some. If you don’t then I recommend reading the pragm
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く