Sha256: a7a6939a1268a2ce7bc0ea232f1916fb9b73b9a1458f0573f04ff9ddde636233
Contents?: true
Size: 1.19 KB
Versions: 8
Compression:
Stored size: 1.19 KB
Contents
require 'pp' require 'pathname' require 'rubygems' require 'adapter/memory' root_path = Pathname(__FILE__).dirname.join('..').expand_path lib_path = root_path.join('lib') $:.unshift(lib_path) require 'toystore' ################################################################## # An example of all the goodies you get by including Toy::Object # ################################################################## class Person include Toy::Object attribute :name, String attribute :age, Integer end # Pretty class inspecting pp Person john = Person.new(:name => 'John', :age => 30) steve = Person.new(:name => 'Steve', :age => 31) # Pretty inspecting pp john # Attribute dirty tracking john.name = 'NEW NAME!' pp john.changes # {"name"=>["John", "NEW NAME!"], "age"=>[nil, 30]} pp john.name_changed? # true # Equality goodies pp john.eql?(john) # true pp john.eql?(steve) # false pp john == john # true pp john == steve # false # Cloning pp john.clone # Inheritance class AwesomePerson < Person end pp Person.attributes.keys.sort # ["age", "id", "name"] pp AwesomePerson.attributes.keys.sort # ["age", "id", "name", "type"] # Serialization puts john.to_json puts john.to_xml
Version data entries
8 entries across 8 versions & 1 rubygems