Module: TTY2::Utils

Defined in:
lib/tty2/prompt/utils.rb

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.blank?(value) ⇒ Boolean

Check if value is nil or an empty string

Parameters:

  • value (Object)

    the value to check

Returns:

  • (Boolean)


31
32
33
# File 'lib/tty2/prompt/utils.rb', line 31

def blank?(value)
  value.nil? || BLANK_REGEX === value
end

.deep_copy(object) ⇒ Object

Deep copy object



38
39
40
# File 'lib/tty2/prompt/utils.rb', line 38

def deep_copy(object)
  Marshal.load(Marshal.dump(object))
end

.extract_options(args) ⇒ Object

Extract options hash from array argument

Parameters:

  • args (Array[Object])


14
15
16
17
# File 'lib/tty2/prompt/utils.rb', line 14

def extract_options(args)
  options = args.last
  options.respond_to?(:to_hash) ? options.to_hash.dup : {}
end

.extract_options!(args) ⇒ Object



19
20
21
# File 'lib/tty2/prompt/utils.rb', line 19

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