module Chemlab::Attributable
Attributable
module @example
class MyClass include Attributable attribute :url attribute :id attribute :name do 'test' end
Public Class Methods
attribute(name) { || ... }
click to toggle source
# File lib/chemlab/attributable.rb, line 16 def self.attribute(name) default_value = nil default_value = yield if block_given? define_method(name) do instance_variable_get("@#{name}") || instance_variable_set( "@#{name}", default_value ) end end
included(base)
click to toggle source
# File lib/chemlab/attributable.rb, line 14 def self.included(base) base.class_eval do def self.attribute(name) default_value = nil default_value = yield if block_given? define_method(name) do instance_variable_get("@#{name}") || instance_variable_set( "@#{name}", default_value ) end end end end