Class: Class

Inherits:
Object
  • Object
show all
Defined in:
lib/dsl/monkeypatches.rb

Overview

Helpers for calling methods and instantiate class silently, even if there are arguments to be passed to constructor/method. The main idea is to try to guess the parameters, awaited by method, generate randoms for them and finally call the method on the singleton instance of this class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#Object

TODO:

Maybe we need to overwrite setter for this variable to avoid weird settings like String.★ = Fixnum.new

Note:

There is a possibility to explicitely set the singleton instance, in which case all the methods will be called on it.

Instance of a class, lazy initialized with guessed parameters. Cached.

See Also:



237
238
239
# File 'lib/dsl/monkeypatches.rb', line 237

def 
  @★
end

#Object (readonly)

The result of last call to method with with fake params. Cached.

See Also:



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

def 
  @☆
end

Instance Method Details

#(*args) ⇒ Instance

Instantiates the class with applicable random value.

Parameters:

  • args (Array)

    if passed, used as sceleton for a call to #∀ method.

Returns:

  • (Instance)

    a random value of this Class class.



258
259
260
261
262
263
264
265
266
267
# File 'lib/dsl/monkeypatches.rb', line 258

def  *args
  begin
    inst = self.
    raise NotImplementedError.new("The class should implement `∀` instance method") \
      unless inst.respond_to? :∀
    inst. *args
  rescue Exception => e
    raise NotImplementedError.new("No way: #{e}")
  end
end

#Object

Tries to make a new instance of a class



243
244
245
246
# File 'lib/dsl/monkeypatches.rb', line 243

def 
  fake_parameters unless @★
  @★
end

#(m = :to_s) ⇒ Object

Tries to call a method m on a class.

Parameters:

  • m (Symbol) (defaults to: :to_s)

    the method to be called.

Returns:

  • (Object)

    the result of call to method m



251
252
253
# File 'lib/dsl/monkeypatches.rb', line 251

def  m = :to_s
  .send(m, *fake_parameters(:m => m))
end