Sha256: 0bf549c017d695edb100dc6f996e2cc27a43bf789b34c655b59c4a44131c7574

Contents?: true

Size: 399 Bytes

Versions: 10

Compression:

Stored size: 399 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

10 entries across 10 versions & 1 rubygems

Version Path
facets-2.8.4 lib/core/facets/kernel/respond.rb
facets-2.8.3 lib/core/facets/kernel/respond.rb
facets-2.8.2 lib/core/facets/kernel/respond.rb
facets-2.8.1 lib/core/facets/kernel/respond.rb
facets-2.8.0 lib/core/facets/kernel/respond.rb
facets-2.7.0 lib/core/facets/kernel/respond.rb
facets-2.6.0 lib/core/facets/kernel/respond.rb
facets-2.5.1 lib/core/facets/kernel/respond.rb
facets-2.5.0 lib/core/facets/kernel/respond.rb
facets-2.5.2 lib/core/facets/kernel/respond.rb