Class: RubyArguments

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

Direct Known Subclasses

NullArguments

Defined Under Namespace

Modules: Exceptions Classes: NullArguments

Constant Summary collapse

VERSION =
"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)


81
82
83
84
85
# File 'lib/ruby_arguments.rb', line 81

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

Instance Attribute Details

#argsObject (readonly)



58
59
60
# File 'lib/ruby_arguments.rb', line 58

def args
  @args
end

#blockObject (readonly)



72
73
74
# File 'lib/ruby_arguments.rb', line 72

def block
  @block
end

#kwargsObject (readonly)



65
66
67
# File 'lib/ruby_arguments.rb', line 65

def kwargs
  @kwargs
end

Class Method Details

.null_argumentsRubyArguments::NullArguments



92
93
94
# File 'lib/ruby_arguments.rb', line 92

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

Instance Method Details

#==(other) ⇒ Boolean?

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)


168
169
170
171
172
173
174
175
176
# File 'lib/ruby_arguments.rb', line 168

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:



155
156
157
158
159
160
161
# File 'lib/ruby_arguments.rb', line 155

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)


109
110
111
112
113
114
115
# File 'lib/ruby_arguments.rb', line 109

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

  false
end

#blank?Booleam

Returns:

  • (Booleam)


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

def blank?
  none?
end

#deconstructArray

Returns:

  • (Array)


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

def deconstruct
  [args, kwargs, block]
end

#deconstruct_keys(keys) ⇒ Hash

Parameters:

  • keys (Array<Symbol>, nil)

Returns:

  • (Hash)


214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/ruby_arguments.rb', line 214

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)


129
130
131
# File 'lib/ruby_arguments.rb', line 129

def empty?
  none?
end

#eql?(other) ⇒ Boolean?

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)


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

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)


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

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

#none?Booleam

Returns:

  • (Booleam)


121
122
123
# File 'lib/ruby_arguments.rb', line 121

def none?
  !any?
end

#null_arguments?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/ruby_arguments.rb', line 101

def null_arguments?
  false
end

#present?Booleam

Returns:

  • (Booleam)


137
138
139
# File 'lib/ruby_arguments.rb', line 137

def present?
  any?
end