Module: Dangerless

Defined in:
lib/dangerless.rb

Overview

Adds Safe Cloning Methods Automatically from Existing Dangerous ! Methods

Class Method Summary collapse

Class Method Details

.included(parent) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/dangerless.rb', line 5

def self.included(parent)
  parent.instance_methods.each do |method|
    method = method.to_s
    next unless method.end_with? '!'
    define_method :"#{method.chomp('!')}" do |*params|
      copy = clone
      copy.send(method, *params)
      copy
    end
  end
end