Class: RubyArguments

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_arguments.rb,
lib/ruby_arguments/version.rb

Overview

Author:

Direct Known Subclasses

NullArguments

Defined Under Namespace

Modules: Exceptions Classes: NullArguments

Constant Summary collapse

VERSION =

Returns:

  • (String)

Since:

  • 1.1.0

"1.1.0"

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)

Since:

  • 1.0.0



114
115
116
117
118
# File 'lib/ruby_arguments.rb', line 114

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

Instance Attribute Details

#argsObject (readonly)

Since:

  • 1.0.0



88
89
90
# File 'lib/ruby_arguments.rb', line 88

def args
  @args
end

#blockObject (readonly)

Since:

  • 1.0.0



104
105
106
# File 'lib/ruby_arguments.rb', line 104

def block
  @block
end

#kwargsObject (readonly)

Since:

  • 1.0.0



96
97
98
# File 'lib/ruby_arguments.rb', line 96

def kwargs
  @kwargs
end

Class Method Details

.null_argumentsRubyArguments::NullArguments Also known as: nil_arguments

Returns:

Since:

  • 1.0.0



126
127
128
# File 'lib/ruby_arguments.rb', line 126

def null_arguments
  @null_arguments ||= ::RubyArguments::NullArguments.new
end

Instance Method Details

#==(other) ⇒ Boolean?

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)

Since:

  • 1.0.0



230
231
232
233
234
235
236
237
238
# File 'lib/ruby_arguments.rb', line 230

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.

Parameters:

  • key (Integer, Symbol)

Returns:

  • (Object)

    Can be any type.

Raises:

Since:

  • 1.0.0



216
217
218
219
220
221
222
# File 'lib/ruby_arguments.rb', line 216

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

#any?Booleam

Returns:

  • (Booleam)

Since:

  • 1.0.0



165
166
167
168
169
170
171
# File 'lib/ruby_arguments.rb', line 165

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

  false
end

#blank?Booleam

Returns:

  • (Booleam)

Since:

  • 1.0.0



205
206
207
# File 'lib/ruby_arguments.rb', line 205

def blank?
  none?
end

#deconstructArray

Returns:

  • (Array)

Since:

  • 1.0.0



270
271
272
# File 'lib/ruby_arguments.rb', line 270

def deconstruct
  [args, kwargs, block]
end

#deconstruct_keys(keys) ⇒ Hash

Parameters:

  • keys (Array<Symbol>, nil)

Returns:

  • (Hash)

Since:

  • 1.0.0



280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/ruby_arguments.rb', line 280

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

#empty?Booleam

Returns:

  • (Booleam)

Since:

  • 1.0.0



187
188
189
# File 'lib/ruby_arguments.rb', line 187

def empty?
  none?
end

#eql?(other) ⇒ Boolean?

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)

Since:

  • 1.0.0



246
247
248
249
250
251
252
253
254
# File 'lib/ruby_arguments.rb', line 246

def eql?(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

#hashInteger

Returns:

  • (Integer)

Since:

  • 1.0.0



261
262
263
# File 'lib/ruby_arguments.rb', line 261

def hash
  [self.class, args, kwargs, block].hash
end

#none?Booleam

Returns:

  • (Booleam)

Since:

  • 1.0.0



178
179
180
# File 'lib/ruby_arguments.rb', line 178

def none?
  !any?
end

#null_arguments?Boolean Also known as: nil_arguments?

Returns:

  • (Boolean)

Since:

  • 1.0.0



146
147
148
# File 'lib/ruby_arguments.rb', line 146

def null_arguments?
  false
end

#present?Booleam

Returns:

  • (Booleam)

Since:

  • 1.0.0



196
197
198
# File 'lib/ruby_arguments.rb', line 196

def present?
  any?
end