Sha256: cd680c27af2807f147c4d2de061ee9ccea625521a6eae5ec570bc5113d02bef4

Contents?: true

Size: 931 Bytes

Versions: 4

Compression:

Stored size: 931 Bytes

Contents

module Vega
  module MethodHelpers
    private

    def scalar_methods(*methods)
      methods.each do |method|
        define_method("#{method}!") do |value|
          @spec[method] = value
          self
        end
        immutable_method(method)
      end
    end

    def hash_methods(*methods)
      methods.each do |method|
        define_method("#{method}!") do |value|
          (@spec[method] ||= {}).merge!(value)
          self
        end
        immutable_method(method)
      end
    end

    def array_methods(*methods)
      methods.each do |method|
        define_method("#{method}!") do |value|
          value = [value] unless value.is_a?(Array)
          (@spec[method] ||= []).concat(value)
          self
        end
        immutable_method(method)
      end
    end

    def immutable_method(method)
      define_method(method) do |value|
        dup.send("#{method}!", value)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vega-0.4.0 lib/vega/method_helpers.rb
vega-0.3.2 lib/vega/method_helpers.rb
vega-0.3.1 lib/vega/method_helpers.rb
vega-0.3.0 lib/vega/method_helpers.rb