Class: Class
- Inherits:
-
Object
- Object
- Class
- 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
-
#★ ⇒ Object
Instance of a class, lazy initialized with guessed parameters.
-
#☆ ⇒ Object
readonly
The result of last call to method with with fake params.
Instance Method Summary collapse
-
#∀(*args) ⇒ Instance
Instantiates the class with applicable random value.
-
#☎ ⇒ Object
Tries to make a new instance of a class.
-
#☏(m = :to_s) ⇒ Object
Tries to call a method
m
on a class.
Instance Attribute Details
#★ ⇒ Object
Maybe we need to overwrite setter for this variable to avoid weird settings like String.★ = Fixnum.new
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.
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.
240 241 242 |
# File 'lib/dsl/monkeypatches.rb', line 240 def ☆ @☆ end |
Instance Method Details
#∀(*args) ⇒ Instance
Instantiates the class with applicable random value.
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.
251 252 253 |
# File 'lib/dsl/monkeypatches.rb', line 251 def ☏ m = :to_s ☎.send(m, *fake_parameters(:m => m)) end |