LoginSignup
5
1

More than 5 years have passed since last update.

Ruby の () の戻り値

Last updated at Posted at 2017-08-25

ブログ記事からの転載です。

Ruby だと () の戻り値は nil になるらしい。

p ()      # => nil
p ().nil? # true

ほぼ使うことはないだろうけど知らなかった(そもそも () だけ評価出来ると思ってなかった。

ちなみに #call が呼び出されるわけではない。

class X
    def call
        "call"
    end

    def func
        p self.()   # => "call"
        p ()        # => nil
    end
end

X.new.func
5
1
2

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
5
1