seguente frammento di codice da rotaieQual è l'operatore <= su Ruby Classes?
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
Avviso all'operatore < =
che cos'è?
Perché pensi che sia "stravagante sovraccarico di operatori"? La relazione di ereditarietà impone un ordinamento parziale sulle classi e, in generale, il simbolo utilizzato per rappresentare le relazioni che impongono ordinamenti parziali è '<=' (o piuttosto '≤' ma mentre questo è un nome di metodo valido in Ruby, non è valido nome dell'operatore). Sei corretto nella misura in cui il solito operatore per denotare una relazione di sottotipo è '<:', ma non è né un metodo valido né un nome operatore in Ruby, quindi personalmente ritengo che '<=' sia abbastanza buono. Sicuramente batte il comune abuso dell'uso di '+' per set union (che dovrebbe essere '∪'). –