Sha256: afdc1193683ac68d9e781cd1a7f85e7a19717d6f6b2d060dfad31f93df3cbfd0

Contents?: true

Size: 400 Bytes

Versions: 7

Compression:

Stored size: 400 Bytes

Contents

module Kernel

  # Like #respond_to? but returns the result of the call
  # if it does indeed respond.
  #
  #   class X
  #     def f; "f"; end
  #   end
  #
  #   x = X.new
  #   x.respond(:f)  #=> "f"
  #   x.respond(:g)  #=> nil
  #
  #  CREDIT: Trans

  def respond(sym, *args)
    return nil if not respond_to?(sym)
    send(sym, *args)
  end

  alias_method :respond_with_value, :respond

end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
facets-2.4.0 lib/facets/kernel/respond.rb
facets-2.4.1 lib/facets/kernel/respond.rb
facets-2.4.3 lib/core/facets/kernel/respond.rb
facets-2.4.2 lib/core/facets/kernel/respond.rb
facets-2.4.4 lib/core/facets/kernel/respond.rb
facets-2.4.5 lib/core/facets/kernel/respond.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/core/facets/kernel/respond.rb