following snippet is from rails code
def rescue_from(*klasses, &block)
options = klasses.extract_options!
unless options.has_key?(:with)
if block_given?
options[:with] = block
else
raise ArgumentError, "Need a handler. Supply an options hash that has a :with key as the last argument."
end
end
klasses.each do |klass|
key = if klass.is_a?(Class) && klass <= Exception
klass.name
elsif klass.is_a?(String)
klass
else
raise ArgumentError, "#{klass} is neither an Exception nor a String"
end
# put the new handler at the end because the list is read in reverse
self.rescue_handlers += [[key, options[:with]]]
end
end
end
Notice the operator <=
what is that?
Greater Than(>) operator checks whether the first operand is greater than the second operand. If so, it returns true. Otherwise it returns false. For example, 6>5 will return true.
In Ruby, the === operator is used to test equality within a when clause of a case statement. In other languages, the above is true. To my knowledge, Ruby doesn't have true operators, they are all methods which are invoked on the LHS of the expression, passing in the RHS of the expression.
Triple Equals Operator (More Than Equality) Our last operator today is going to be about the triple equals operator ( === ).
To define unary + and unary – operators, use method names +@ and -@ to avoid ambiguity with the binary operators that use the same symbols. The != and !~ operators are defined as the negation of the == and =~ operators. In Ruby 1.9, you can redefine !=
See http://ruby-doc.org/core/classes/Module.html#M001669 for documentation on all the comparison operators exposed by Modules (and therefore Classes).
In this specific case: "Returns true if mod is a subclass of other or is the same as other. Returns nil if there‘s no relationship between the two. (Think of the relationship in terms of the class definition: "class A < B" implies "A < B")."
It's comparable to the is_a?
method which returns true if the receiver class is a subclass of the argument; consider:
Fixnum.superclass # => Integer
Fixnum <= Integer # => true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With