Sha256: 36e15d2a917a919bc7409a248eb3ed09917b601228860805af45156c8134fa26

Contents?: true

Size: 508 Bytes

Versions: 331

Compression:

Stored size: 508 Bytes

Contents

# frozen_string_literal: true

require 'active_support/core_ext/object/blank'

class Object
  # @return +block.call(self.method_name)+ if +self+ responds to +method_name+, +default_value+
  # otherwise.
  def if_respond(method_name, default_value = nil)
    return default_value unless respond_to?(method_name)

    value = send(method_name)

    block_given? ? yield(value) : value
  end

  # @return +yield+ if +self+ is blank.
  def if_blank
    return yield if blank? && block_given?

    self
  end
end

Version data entries

331 entries across 331 versions & 4 rubygems

Version Path
eac_ruby_utils-0.124.0 lib/eac_ruby_utils/patches/object/if_respond.rb
eac_tools-0.97.2 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb
eac_ruby_utils-0.123.0 lib/eac_ruby_utils/patches/object/if_respond.rb
eac_ruby_utils-0.121.0 lib/eac_ruby_utils/patches/object/if_respond.rb
eac_ruby_utils-0.120.0 lib/eac_ruby_utils/patches/object/if_respond.rb
eac_tools-0.76.1 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb
eac_tools-0.76.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb
eac_tools-0.75.2 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb
eac_ruby_utils-0.119.2 lib/eac_ruby_utils/patches/object/if_respond.rb
eac_tools-0.75.1 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb
eac_tools-0.75.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb
eac_ruby_utils-0.119.1 lib/eac_ruby_utils/patches/object/if_respond.rb
eac_tools-0.74.1 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb
eac_tools-0.74.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb
eac_tools-0.73.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb
eac_ruby_utils-0.119.0 lib/eac_ruby_utils/patches/object/if_respond.rb
eac_tools-0.72.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb
eac_ruby_utils-0.118.1 lib/eac_ruby_utils/patches/object/if_respond.rb
eac_ruby_utils-0.118.0 lib/eac_ruby_utils/patches/object/if_respond.rb
eac_tools-0.70.1 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb