class Object

Public Class Methods

chain_if(switch, operator, *args) click to toggle source
# File lib/creative_rails_utilities/object.rb, line 3
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

Public Instance Methods

chain_if(switch, operator, *args) click to toggle source
# File lib/creative_rails_utilities/object.rb, line 17
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 Instance Methods

raise_chain_if_argument_error() click to toggle source
# File lib/creative_rails_utilities/object.rb, line 32
def raise_chain_if_argument_error
  raise ArgumentError.new(":operator argument is bad, use a Proc ar a Symbol.")
end