Class: Object

Inherits:
BasicObject
Defined in:
lib/acts_as_chain.rb

Class Method Summary collapse

Class Method Details

.acts_as_chain(*args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/acts_as_chain.rb', line 4

def self.acts_as_chain(*args)
  args.each do |method|
    define_method method do |*args|
      if args.empty?
        instance_variable_get("@#{method.to_s}")
      elsif args.one?
        tap { 
          instance_variable_set("@#{method.to_s}", args.first)
        }
      else
        tap { 
          instance_variable_set("@#{method.to_s}", args)
        }
      end
    end
  end
end