Sha256: 0df3d921c82736e70bac1635405d10b6f1f9cfbf00094447d480b93ebf06bc04

Contents?: true

Size: 896 Bytes

Versions: 10

Compression:

Stored size: 896 Bytes

Contents

# frozen_string_literal: true

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

10 entries across 10 versions & 2 rubygems

Version Path
pokedex-terminal-0.2.8 vendor/bundle/ruby/2.7.0/gems/tty-prompt-0.21.0/lib/tty/prompt/utils.rb
pokedex-terminal-0.2.7 vendor/bundle/ruby/2.7.0/gems/tty-prompt-0.21.0/lib/tty/prompt/utils.rb
pokedex-terminal-0.2.6 vendor/bundle/ruby/2.7.0/gems/tty-prompt-0.21.0/lib/tty/prompt/utils.rb
pokedex-terminal-0.2.5 vendor/bundle/ruby/2.7.0/gems/tty-prompt-0.21.0/lib/tty/prompt/utils.rb
pokedex-terminal-0.2.4 vendor/bundle/ruby/2.7.0/gems/tty-prompt-0.21.0/lib/tty/prompt/utils.rb
tty-prompt-0.21.0 lib/tty/prompt/utils.rb
tty-prompt-0.20.0 lib/tty/prompt/utils.rb
tty-prompt-0.19.0 lib/tty/prompt/utils.rb
tty-prompt-0.18.1 lib/tty/prompt/utils.rb
tty-prompt-0.18.0 lib/tty/prompt/utils.rb