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.0.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



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

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

Instance Attribute Details

#argsObject (readonly)

Since:

  • 1.0.0



78
79
80
# File 'lib/ruby_arguments.rb', line 78

def args
  @args
end

#blockObject (readonly)

Since:

  • 1.0.0



94
95
96
# File 'lib/ruby_arguments.rb', line 94

def block
  @block
end

#kwargsObject (readonly)

Since:

  • 1.0.0



86
87
88
# File 'lib/ruby_arguments.rb', line 86

def kwargs
  @kwargs
end

Class Method Details

.null_argumentsRubyArguments::NullArguments

Returns:

Since:

  • 1.0.0



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

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



200
201
202
203
204
205
206
207
208
# File 'lib/ruby_arguments.rb', line 200

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



186
187
188
189
190
191
192
# File 'lib/ruby_arguments.rb', line 186

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



135
136
137
138
139
140
141
# File 'lib/ruby_arguments.rb', line 135

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



175
176
177
# File 'lib/ruby_arguments.rb', line 175

def blank?
  none?
end

#deconstructArray

Returns:

  • (Array)

Since:

  • 1.0.0



240
241
242
# File 'lib/ruby_arguments.rb', line 240

def deconstruct
  [args, kwargs, block]
end

#deconstruct_keys(keys) ⇒ Hash

Parameters:

  • keys (Array<Symbol>, nil)

Returns:

  • (Hash)

Since:

  • 1.0.0



250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/ruby_arguments.rb', line 250

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



157
158
159
# File 'lib/ruby_arguments.rb', line 157

def empty?
  none?
end

#eql?(other) ⇒ Boolean?

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)

Since:

  • 1.0.0



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

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



231
232
233
# File 'lib/ruby_arguments.rb', line 231

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

#none?Booleam

Returns:

  • (Booleam)

Since:

  • 1.0.0



148
149
150
# File 'lib/ruby_arguments.rb', line 148

def none?
  !any?
end

#null_arguments?Boolean

Returns:

  • (Boolean)

Since:

  • 1.0.0



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

def null_arguments?
  false
end

#present?Booleam

Returns:

  • (Booleam)

Since:

  • 1.0.0



166
167
168
# File 'lib/ruby_arguments.rb', line 166

def present?
  any?
end