Sha256: cf6a72af405e6cb3b18556ced92e0caa6c2f5c5b5dc1da221ab4912808dcc2f6

Contents?: true

Size: 263 Bytes

Versions: 10

Compression:

Stored size: 263 Bytes

Contents

module Kernel

  # Try a method.
  #
  #   @person ? @person.name : nil
  # vs
  #
  #   @person.try(:name)
  #
  # CREDIT: Chris Wanstrath

  def try(method, default=nil)
    if respond_to? method
      send method
    else
      default
    end
  end

end





Version data entries

10 entries across 10 versions & 1 rubygems

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