Sha256: 2981fdea736601eba6f9c191128ea2b66ffd8a84508052214ea77f59e4611c18

Contents?: true

Size: 433 Bytes

Versions: 4

Compression:

Stored size: 433 Bytes

Contents

module AttributeChain
  def self.included(base)
    base.extend(ClassMethods)
  end
  
  module ClassMethods
    def attr_chain(*methods)
      methods.each do |m|
        define_method(m) do |set|
          ivar = "@#{m}"
          unless set.nil?
            instance_variable_set(ivar, set)
            return self
          else
            return instance_variable_get(ivar)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
benschwarz-attr-chain-0.1.0 lib/attr_chain.rb
benschwarz-attr-chain-0.1.1 lib/attr_chain.rb
benschwarz-attr-chain-0.1.2 lib/attr-chain.rb
attr-chain-0.1.2 lib/attr-chain.rb