LoginSignup
2
0

More than 5 years have passed since last update.

Rubyでa == 1 && a == 2 && a == 3をTrueにする

Posted at

はじめに

何番煎じかわからないですが、rubyでやってみた記事が見つからなかったのでやってみました。
結論から言うと、言語仕様で演算子のオーバーライドが許可されてるので、非常に簡単でした。

コード

class MyClass
    def ==(other)
        true
    end
end

a = MyClass.new

puts a == 1 && a == 2 && a == 3

元ネタ

Can (a== 1 && a ==2 && a==3) ever evaluate to true?

2
0
0

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
2
0