Class: ConvenientService::Support::Arguments
- Inherits:
-
Object
- Object
- ConvenientService::Support::Arguments
- 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
Defined Under Namespace
Modules: Exceptions Classes: NullArguments
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#kwargs ⇒ Object
readonly
Returns the value of attribute kwargs.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#[](key) ⇒ Object
Can be any type.
- #any? ⇒ Booleam
- #deconstruct ⇒ Array
- #deconstruct_keys(keys) ⇒ Hash
- #initialize(*args, **kwargs, &block) ⇒ void constructor
- #none? ⇒ Booleam
- #null_arguments? ⇒ Boolean
Constructor Details
#initialize(*args, **kwargs, &block) ⇒ void
38 39 40 41 42 |
# File 'lib/convenient_service/support/arguments.rb', line 38 def initialize(*args, **kwargs, &block) @args = args @kwargs = kwargs @block = block end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
18 19 20 |
# File 'lib/convenient_service/support/arguments.rb', line 18 def args @args end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
30 31 32 |
# File 'lib/convenient_service/support/arguments.rb', line 30 def block @block end |
#kwargs ⇒ Object (readonly)
Returns the value of attribute kwargs.
24 25 26 |
# File 'lib/convenient_service/support/arguments.rb', line 24 def kwargs @kwargs end |
Class Method Details
.null_arguments ⇒ ConvenientService::Support::Arguments::NullArguments
48 49 50 |
# File 'lib/convenient_service/support/arguments.rb', line 48 def null_arguments @null_arguments ||= Support::Arguments::NullArguments.new end |
Instance Method Details
#==(other) ⇒ Boolean
97 98 99 100 101 102 103 104 105 |
# File 'lib/convenient_service/support/arguments.rb', line 97 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.
85 86 87 88 89 90 91 |
# File 'lib/convenient_service/support/arguments.rb', line 85 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
63 64 65 66 67 68 69 |
# File 'lib/convenient_service/support/arguments.rb', line 63 def any? return true if args.any? return true if kwargs.any? return true if block false end |
#deconstruct ⇒ Array
Note:
Expected to be called only from pattern matching. Avoid direct usage of this method.
114 115 116 |
# File 'lib/convenient_service/support/arguments.rb', line 114 def deconstruct [args, kwargs, block] end |
#deconstruct_keys(keys) ⇒ Hash
Note:
Expected to be called only from pattern matching. Avoid direct usage of this method.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/convenient_service/support/arguments.rb', line 126 def deconstruct_keys(keys) keys ||= [:args, :kwargs, :block] keys.each_with_object({}) do |key, hash| case key when :args hash[key] = args when :kwargs hash[key] = kwargs when :block hash[key] = block end end end |
#none? ⇒ Booleam
74 75 76 |
# File 'lib/convenient_service/support/arguments.rb', line 74 def none? !any? end |
#null_arguments? ⇒ Boolean
56 57 58 |
# File 'lib/convenient_service/support/arguments.rb', line 56 def null_arguments? false end |