lib/aqua/support/initializers.rb in baccigalupi-aqua-0.1.4 vs lib/aqua/support/initializers.rb in baccigalupi-aqua-0.1.5

- old
+ new

@@ -1,9 +1,12 @@ # AQUA INITIALIZATION # Some object store state in a fundamental way, not in instance variables, that needs to be initialized. # Examples: Array, Numeric types, Hashes, Time ... -# You can make any object requiring this initialization savable to aqua by adding the following methods: +# You can make any object requiring this initialization savable to aqua by +# * including the Aqua::To module and extending the Aqua::From module +# * building your own methods for #to_aqua, #to_aqua_init, MyClass.aqua_init +# See set.rb in this file for more an example module Aqua module To def to_aqua( base_object ) hash = { 'class' => self.class.to_s, @@ -25,11 +28,11 @@ new( init ) end end # From end -[ TrueClass, FalseClass, Time, Date, Fixnum, Bignum, Float, Rational, Hash, Array, OpenStruct].each do |klass| +[ TrueClass, FalseClass, Time, Date, Fixnum, Bignum, Float, Rational, Hash, Array, OpenStruct, Range].each do |klass| klass.class_eval do include Aqua::To extend Aqua::From end end @@ -72,10 +75,16 @@ class Float def self.aqua_init( init ) init.to_f end -end +end + +class Range + def self.aqua_init( init ) + eval( init ) + end +end class Rational def to_aqua_init( base_object ) self.to_s.match(/(\d*)\/(\d*)/).to_a.slice(1,2) end \ No newline at end of file