Sha256: c0391a6ebd4fa7d4e851c5cead70a71c388c6fda32138e44f879cc8866b89956

Contents?: true

Size: 838 Bytes

Versions: 7

Compression:

Stored size: 838 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? || 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

7 entries across 7 versions & 2 rubygems

Version Path
tty-prompt-0.23.1 lib/tty/prompt/utils.rb
tty-prompt-0.23.0 lib/tty/prompt/utils.rb
lotrd-0.1.9 vendor/cache/ruby/2.6.0/gems/tty-prompt-0.22.0/lib/tty/prompt/utils.rb
lotrd-0.1.8 vendor/cache/ruby/2.6.0/gems/tty-prompt-0.22.0/lib/tty/prompt/utils.rb
lotrd-0.1.6 vendor/cache/ruby/2.6.0/gems/tty-prompt-0.22.0/lib/tty/prompt/utils.rb
lotrd-0.1.5 vendor/cache/ruby/2.6.0/gems/tty-prompt-0.22.0/lib/tty/prompt/utils.rb
tty-prompt-0.22.0 lib/tty/prompt/utils.rb