LoginSignup
11

More than 5 years have passed since last update.

役に立たないどころか知ってるとサボってると思われる知識

Last updated at Posted at 2015-06-22

謎メソッド forty_two()

Find the forty-second record. Also known as accessing “the reddit”. If no order is defined it will order by primary key.

42番目のレコードいわゆる"reddit"にアクセスする。
特に指定がなければなければ出力はprimary keyで並ぶ

Person.forty_two 
=> returns the forty-second object fetched by SELECT * FROM people
Person.offset(3).forty_two 
=> returns the forty-second object from OFFSET 3 (which is OFFSET 44)
Person.where(["user_name = :u", { u: user_name }]).forty_two

こうやって使うのかな???

if params[:question] == "life, universe and everything"
 Answers.forty_two
end

「宇宙とか人生とか地球とかそんなんもろもろ全部に対する答えって出せないの?」

とクライアントに言われた時に役に立ちそうですね。(ねーよ)

追記
Quora: forty_twoってなんでThe Redditメソッドなんて言われてるの?
制作者がRedditのスレ民の需要に応えたとか何とか書いてあります。

ネタはいいから・・・ as_json(options = nil)

Returns a hash representing the model. Some configuration can be passed through options.

モデルに対して使うとハッシュが帰ってくるみたいです。

user = User.find(1)
user.as_json

とすると

# => { "id" => 1, "name" => "Konata Izumi", "age" => 16,
#     "created_at" => "2006/08/01", "awesome" => true}

ふつーに便利そうですね。

あれ・・・?

# => { "id" => 1, "name" => "Konata Izumi", "age" => 16,

ん?

"name" => "Konata Izumi"

どうでもいいですがこなたって変わった名前ですね。
えー こなた えー えー

Konata Izumi

(;´Д`) オウフ・・・・・・・・・

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11