24 Feb '13, 12pm

Rubyist Magazine - Ruby 2.0.0 のキーワード引数

このメソッドは引数無しで呼び出すと、level: "ERROR", time: Time.now が渡されたのと同じように動きます。 log("Hello!") #=> Mon Feb 18 01:46:22 2013 [ERROR] Hello! log("Hello!", level: "ERROR", time: Time.now) #=> Mon Feb 18 01:46:22 2013 [ERROR] Hello! キーワード引数の順番は順不同です。(ただし、他の種類の引数と順番を変えることはできません) log("Hello!", time: Time.now, level: "ERROR") #=> Mon Feb 18 01:46:22 2013 [ERROR] Hello! log(level: "ERROR", time: Time.now, "Hello!") # これはダメ 片方だけ指定することもできます。 log("Hello!", level: "INFO") #=> Mon Feb 18 01:46:22 2013 [INFO] Hello! 知らない引数を与えると例外を投げてくれます。 log("Hello!", date: Time.new) #=> unknown keyword: date 例外にしてほしくないんだ!という人は、** 引数で残りのハッシュを明示的に受け取ればいいです。 def log(msg, level: "ERROR", time: Time.now, **kwrest) puts "#{ time.ctime } [#{ level }] #{ msg }" end log("Hello!", date: Time.now) #=> Mon Feb 18 01:46:22 2013 [ERROR] Hello! また、オプション引数や可変長引数などと組み合わせることも可能です。(極端なのはあまりお勧めしませんが) def f(a, b, c, m = 1, n = 1, *rest...

Full article: http://jp.rubyist.net/magazine/?0041-200Special-kwarg

Tweets

ruby2.0に対応させるときの注意点まとめ / “Rubyist Magazine - Ru...

jp.rubyist.net 24 Feb '13, 10am

Magic Comment を書いていないファイルの文字列リテラルのエンコーディング (default script encoding) が UTF-8 に変更されました。[#6679] Ruby 1.9 においては、default scrip...

Rubyist Magazine - Ruby 2.0.0 リリース特集

jp.rubyist.net 24 Feb '13, 9am

I've known Ruby since she was just 4 or 5 years old. Of course, I knew her parents, Smalltalk and Perl, and had a nodding ...

Ruby 2.0.0

jp.rubyist.net 24 Feb '13, 9am

Rubyist Hotlinks 【第 31 回】 樽家昌也さん Rubyist へのインタビュー企画。今回はたるいさんにお話を伺いました。(難易度:ポケコン) Ruby 2.0.0 リリース特集 編集:ささだ 2013 年 2 月 24 日に...

読んでる→Rubyist Magazine - Ruby 2.0.0 の DTrace の紹介

jp.rubyist.net 24 Feb '13, 10am

以下のプログラムを t.rb というファイルとして保存します。 class Foo def hello puts :hello end end 5.times do foo = Foo.new foo.hello sleep 1 end rub...

Yay, #Ruby 2.0.0 is out! With lots of goodies.

ruby-lang.org 24 Feb '13, 6pm

The default encoding for ruby scripts is now UTF-8 [#6679]. Some people report that it affects existing programs, such as ...

“Rubyist Magazine - Ruby 2.0.0 の require”

“Rubyist Magazine - Ruby 2.0.0 の require”

jp.rubyist.net 24 Feb '13, 12pm

files=2000 begin files.times{|i| file = "req/file#{i}.rb" open(file,"wb"){} } rescue end 100.times{ $LOAD_PATH << "/" } #g...

"Ruby 2.0.0 is ready for practical use, and wil...

ruby-lang.org 24 Feb '13, 5pm

The default encoding for ruby scripts is now UTF-8 [#6679]. Some people report that it affects existing programs, such as ...

Ruby 2.0.0 MetaCasts Video Free This Week!

rubyflow.com 25 Feb '13, 3pm

Ruby 2.0.0 MetaCasts Video Free This Week! Posted by markbates on February 25, 2013 — 0 comments To celebrate the release ...

Ruby 2.0

ruby-lang.org 24 Feb '13, 9am

The default encoding for ruby scripts is now UTF-8 [#6679]. Some people report that it affects existing programs, such as ...

2.0.0 特集がおおいけど、咳フリークの人に「咳フリーク以外が読んで楽しめるのか?」と言わし...

jp.rubyist.net 24 Feb '13, 9am

class BDBError < RuntimeError def initialize(bdb) super(bdb.errmsg(bdb.ecode)) end end class BDB < TokyoCabinet::BDB def e...

「Ruby 2.0 に入るはずだった Refinements」Oh.../Rubyist Ma...

jp.rubyist.net 24 Feb '13, 10am

$ ruby -e 'module M; refine String do end; end' -e:1: warning: Refinements are experimental, and the behavior may change i...

Rubyist Magazine - Ruby on Rails: The Bad Parts

jp.rubyist.net 24 Feb '13, 10am

class AcceptAnswerActivity < AbstractActivity attribute :answer attribute :questioner validates_signin_of :questioner vali...

Google Waveの記事 / “Rubyist Magazine - parse.y の歩...

jp.rubyist.net 23 Feb '13, 7am

static NODE* cond_gen(struct parser_params *parser, NODE *node, float maybe) { NODE *mcond; if (node == 0) return 0; if (m...

Becoming a Rubyist

rubyflow.com 26 Feb '13, 1pm

Becoming a Rubyist Posted by bryckbost on February 26, 2013 — 0 comments Just like learning a new spoken language, learnin...

Today's Ruby Weekly is the most release heavy e...

rubyweekly.com 28 Feb '13, 2pm

Last Sunday marked the 20th anniversary of work commencing on Ruby way back in 1993 and it was celebrated in style with th...