Sha256: 17f9697194291677654af7e51af5295c38a72cfc988c329aa01b47d5766e350b
Contents?: true
Size: 922 Bytes
Versions: 7
Compression:
Stored size: 922 Bytes
Contents
class Object def self.chain_if(switch, operator, *args) raise_chain_if_argument_error unless operator.class == Proc || operator.respond_to?(:to_sym) return self unless switch if operator.class == Proc operator.call(self) elsif operator.respond_to?(:to_sym) return self.public_send(operator.to_sym, *args) else raise_chain_if_argument_error end end def chain_if(switch, operator, *args) raise_chain_if_argument_error unless operator.class == Proc || operator.respond_to?(:to_sym) return self unless switch if operator.class == Proc operator.call(self) elsif operator.respond_to?(:to_sym) return self.public_send(operator.to_sym, *args) else raise_chain_if_argument_error end end private def raise_chain_if_argument_error raise ArgumentError.new(":operator argument is bad, use a Proc ar a Symbol.") end end
Version data entries
7 entries across 7 versions & 1 rubygems