Sha256: 5a35bf0760ed7b90ecfe7d2cb285131107225ffde6b44e05f690293a2c768fdb

Contents?: true

Size: 884 Bytes

Versions: 17

Compression:

Stored size: 884 Bytes

Contents

# encoding: utf-8

module TTY
  module Utils
    module_function

    BLANK_REGEX = /\A[[:space:]]*\z/o.freeze

    # Extract options hash from array argument
    #
    # @param [Array[Object]] args
    #
    # @api public
    def extract_options(args)
      options = args.last
      options.respond_to?(:to_hash) ? options.to_hash.dup : {}
    end

    def extract_options!(args)
      args.last.respond_to?(:to_hash) ? args.pop : {}
    end

    # Check if value is nil or an empty string
    #
    # @param [Object] value
    #   the value to check
    #
    # @return [Boolean]
    #
    # @api public
    def blank?(value)
      value.nil? ||
      value.respond_to?(:empty?) && value.empty? ||
      BLANK_REGEX === value
    end

    # Deep copy object
    #
    # @api public
    def deep_copy(object)
      Marshal.load(Marshal.dump(object))
    end
  end # Utils
end # TTY

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
tty-prompt-0.15.0 lib/tty/prompt/utils.rb
tty-prompt-0.14.0 lib/tty/prompt/utils.rb
tty-prompt-0.13.2 lib/tty/prompt/utils.rb
tty-prompt-0.13.1 lib/tty/prompt/utils.rb
tty-prompt-0.13.0 lib/tty/prompt/utils.rb
austb-tty-prompt-0.13.0 lib/tty/prompt/utils.rb
tty-prompt-0.12.0 lib/tty/prompt/utils.rb
tty-prompt-0.11.0 lib/tty/prompt/utils.rb
tty-prompt-0.10.1 lib/tty/prompt/utils.rb
tty-prompt-0.10.0 lib/tty/prompt/utils.rb
tty-prompt-0.9.0 lib/tty/prompt/utils.rb
tty-prompt-0.8.0 lib/tty/prompt/utils.rb
tty-prompt-0.7.1 lib/tty/prompt/utils.rb
tty-prompt-0.7.0 lib/tty/prompt/utils.rb
tty-prompt-0.6.0 lib/tty/prompt/utils.rb
tty-prompt-0.5.0 lib/tty/prompt/utils.rb
tty-prompt-0.4.0 lib/tty/prompt/utils.rb