Fellow Stranger
Fellow Stranger

Reputation: 34053

Does ruby have nor?

Ruby has the conditional unless.

Does it have nor?

E.g.

unless 1 == 2 nor 1 == 3
  "nothing equal"
else
  "something's equal"
end

Upvotes: 0

Views: 1139

Answers (2)

Sophie Alpert
Sophie Alpert

Reputation: 143194

Ruby doesn't have a built-in nor, but you could extend the built-in booleans like so:

class TrueClass
  def nor(other)
    false
  end
end

class FalseClass
  def nor(other)
    !other
  end
end

and then write

unless (1 == 2).nor(1 == 3)
  "nothing equal"
else
  "something's equal"
end

Upvotes: 3

jandresrodriguez
jandresrodriguez

Reputation: 794

Nope... but you can simulate it like this:

unless 1 != 2 && 1 != 3
  "nothing equal"
else
  "something's equal"
end

Upvotes: 1

Related Questions