Class: ConvenientService::Support::Arguments

Inherits:
Object
  • Object
show all
Defined in:
lib/convenient_service/support/arguments.rb,
lib/convenient_service/support/arguments/exceptions.rb,
lib/convenient_service/support/arguments/null_arguments.rb

Direct Known Subclasses

NullArguments

Defined Under Namespace

Modules: Exceptions Classes: NullArguments

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, **kwargs, &block) ⇒ void

Parameters:

  • args (Array<Object>)
  • kwargs (Hash{Symbol => Object})
  • block (Proc, nil)


33
34
35
36
37
# File 'lib/convenient_service/support/arguments.rb', line 33

def initialize(*args, **kwargs, &block)
  @args = args
  @kwargs = kwargs
  @block = block
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



13
14
15
# File 'lib/convenient_service/support/arguments.rb', line 13

def args
  @args
end

#blockObject (readonly)

Returns the value of attribute block.



25
26
27
# File 'lib/convenient_service/support/arguments.rb', line 25

def block
  @block
end

#kwargsObject (readonly)

Returns the value of attribute kwargs.



19
20
21
# File 'lib/convenient_service/support/arguments.rb', line 19

def kwargs
  @kwargs
end

Class Method Details

.null_argumentsConvenientService::Support::Arguments::NullArguments



43
44
45
# File 'lib/convenient_service/support/arguments.rb', line 43

def null_arguments
  @null_arguments ||= Support::Arguments::NullArguments.new
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

  • other (Object)

Returns:

  • (Boolean)


88
89
90
91
92
93
94
95
96
# File 'lib/convenient_service/support/arguments.rb', line 88

def ==(other)
  return unless other.instance_of?(self.class)

  return false if args != other.args
  return false if kwargs != other.kwargs
  return false if block != other.block

  true
end

#[](key) ⇒ Object

Returns Can be any type.

Returns:

  • (Object)

    Can be any type.



76
77
78
79
80
81
82
# File 'lib/convenient_service/support/arguments.rb', line 76

def [](key)
  case key
  when Integer then args[key]
  when Symbol then kwargs[key]
  else ::ConvenientService.raise Exceptions::InvalidKeyType.new(key: key)
  end
end

#any?Booleam

Returns:

  • (Booleam)


58
59
60
61
62
63
64
# File 'lib/convenient_service/support/arguments.rb', line 58

def any?
  return true if args.any?
  return true if kwargs.any?
  return true if block

  false
end

#none?Booleam

Returns:

  • (Booleam)


69
70
71
# File 'lib/convenient_service/support/arguments.rb', line 69

def none?
  !any?
end

#null_arguments?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/convenient_service/support/arguments.rb', line 51

def null_arguments?
  false
end