Sha256: c103550c454d2ba3a222279e8a5d40c27f68e629e40b9ff28a02a34e1dc30d52
Contents?: true
Size: 591 Bytes
Versions: 4
Compression:
Stored size: 591 Bytes
Contents
class Object def stub(methot, value) singleton_methot_exists = respond_to?(methot) && singleton_methods.include?(methot) if singleton_methot_exists original = "__original_#{methot}__" singleton_class.class_eval { alias_method(original, methot) } end define_singleton_method(methot) { |*arguments| value } yield ensure if singleton_methot_exists singleton_class.class_eval do alias_method(methot, original) remove_method(original) end else singleton_class.class_eval { remove_method(methot) } end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
defekt-0.0.7 | lib/defekt/object.rb |
defekt-0.0.6 | lib/defekt/object.rb |
defekt-0.0.5 | lib/defekt/object.rb |
defekt-0.0.4 | lib/defekt/object.rb |