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
282 283 284 285 |
# File 'lib/much-stub.rb', line 282 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
276 277 278 279 280 |
# File 'lib/much-stub.rb', line 276 def self.get_arity(object, method_name) object.method(method_name).arity rescue NameError -1 end |
.get_param_name(param_index) ⇒ Object
287 288 289 290 291 |
# File 'lib/much-stub.rb', line 287 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
268 269 270 271 272 273 274 |
# File 'lib/much-stub.rb', line 268 def self.new(object, method_name) arity = get_arity(object, method_name) params = build_params_from_arity(arity) params << "*args" if arity < 0 params << "&block" params.join(", ") end |