Sha256: 533b8ee029ab13d254e09a9065c6c8484e506d3e2c7c187622f16d1e83630b84

Contents?: true

Size: 360 Bytes

Versions: 1

Compression:

Stored size: 360 Bytes

Contents

require "attr_defaultable/version"

module AttrDefaultable
  def attr_defaultable(att, default)
    define_method(att.to_sym) {
      instance_variable_get("@#{att}".to_sym) || instance_variable_set("@#{att}".to_sym, instance_exec(&default))
    }

    define_method("#{att}=".to_sym) { |val|
      instance_variable_set("@#{att}".to_sym, val)
    }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
attr_defaultable-0.0.3 lib/attr_defaultable.rb