Class: Rubsh::Argument

Inherits:
Object
  • Object
show all
Defined in:
lib/rubsh/argument.rb

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Argument #initialize(name, value) ⇒ Argument

Returns a new instance of Argument.

Overloads:

  • #initialize(name) ⇒ Argument

    Parameters:

    • name (String, Symbol, #to_s)
  • #initialize(name, value) ⇒ Argument

    Parameters:

    • name (String, Symbol, #to_s)
    • value (nil, Boolean, Numeric, String, Symbol, Proc)


9
10
11
12
# File 'lib/rubsh/argument.rb', line 9

def initialize(*args)
  @name, @value = args[0].to_s, args[1]
  @is_positional = args.length < 2
end

Instance Method Details

#compile(long_sep: "=", long_prefix: "--") ⇒ nil, ...

Returns:

  • (nil, String, Array<String>)


21
22
23
24
# File 'lib/rubsh/argument.rb', line 21

def compile(long_sep: "=", long_prefix: "--")
  return compile_positional_argument(@name) if @is_positional
  compile_option_argument(@name, @value, long_sep: long_sep, long_prefix: long_prefix)
end

#value=(value) ⇒ void

This method returns an undefined value.

Raises:

  • (::ArgumentError)


15
16
17
18
# File 'lib/rubsh/argument.rb', line 15

def value=(value)
  raise ::ArgumentError, "cannot assign a new value for positional argument" if @is_positional
  @value = value
end