Module: MuchStub::ParameterList
- Defined in:
- lib/much-stub.rb
Constant Summary collapse
- LETTERS =
("a".."z").to_a.freeze
Class Method Summary collapse
- .build_params_from_arity(arity) ⇒ Object
- .get_arity(object, method_name) ⇒ Object
- .get_param_name(param_index) ⇒ Object
- .new(object, method_name) ⇒ Object
Class Method Details
.build_params_from_arity(arity) ⇒ Object
291 292 293 294 |
# File 'lib/much-stub.rb', line 291 def self.build_params_from_arity(arity) number = arity < 0 ? (arity + 1).abs : arity (0..(number - 1)).map{ |param_index| get_param_name(param_index) } end |
.get_arity(object, method_name) ⇒ Object
285 286 287 288 289 |
# File 'lib/much-stub.rb', line 285 def self.get_arity(object, method_name) object.method(method_name).arity rescue NameError -1 end |
.get_param_name(param_index) ⇒ Object
296 297 298 299 300 |
# File 'lib/much-stub.rb', line 296 def self.get_param_name(param_index) param_index += LETTERS.size # avoid getting 0 for the number of letters number_of_letters, letter_index = param_index.divmod(LETTERS.size) LETTERS[letter_index] * number_of_letters end |
.new(object, method_name) ⇒ Object
277 278 279 280 281 282 283 |
# File 'lib/much-stub.rb', line 277 def self.new(object, method_name) arity = get_arity(object, method_name) params = build_params_from_arity(arity) params << "*pargs, **kargs" if arity < 0 params << "&block" params.join(", ") end |