资 源 简 介
Introducing Valuable
Valuable is a ruby base class that is essentially attr_accessor on steroids. Its aim is to provide Rails-like goodness where ActiveRecord isn"t an option. It intends to use a simple and intuitive interface, allowing you to get on with the logic specific to your application.
Valuable provides the same dry declaration as attr_accessor, but includes default values, light weight type casting, a constructor that accepts an attributes hash, a class-level list of attributes, and an instance-level attributes hash. The type casting can also be used for parsing values.
Example
```
class BaseballPlayer < Valuable
hasvalue :atbats, :klass => Integer
has_value :hits, :klass => Integer
has_value :league, :default => "unknown"
has_value :name
has_value :jersey, :klass => Jersey, :default => "Unknown"
has_collection :teammates
def average
hits/atbats.tof if hits && at_ba