Module: HasInherited::InstanceMethods
- Defined in:
- lib/has_inherited.rb
Instance Method Summary collapse
Instance Method Details
#value ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/has_inherited.rb', line 132 def value case self[:value_type] when 'String' self[:value] when 'Fixnum', 'Bignum' Integer(self[:value]) when 'Float' Float(self[:value]) when 'Symbol' self[:value].to_sym when 'TrueClass' true when 'FalseClass' false when 'Time' Time.parse(self[:value]) when 'Date' Date.parse(self[:value]) when 'DateTime' DateTime.parse(self[:value]) else self[:value] end end |
#value=(new_value) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/has_inherited.rb', line 157 def value=(new_value) if new_value.nil? self[:value] = self.value_type = nil else new_type = new_value.class.to_s case new_type when 'Symbol' new_value = new_value.to_s when 'Fixnum', 'Float', 'Bignum', 'TrueClass', 'FalseClass' new_value = new_value.to_s when 'Time', 'Date', 'DateTime' new_value = new_value.to_s(:rfc822) end self[:value] = new_value self.value_type = new_type end end |