Sha256: 1ba407257823b36ac4738fafdc29b34b17fe65c575104ddd58f7e45a11cfdab0
Contents?: true
Size: 862 Bytes
Versions: 2
Compression:
Stored size: 862 Bytes
Contents
module Schizo # Include Data into a class to give it the ability to be adorned with a Role. module Data # Adorn a Data object with a Role. # # If a block is given, then a facade for _self_ is yielded to the block and the return value # is _self_ with the facade's instance variables copied over to it. # user.name = "callie" # user.as(Poster) do |poster| # poster.name = "coco" # end # user.name # => "coco" # # Without a block, a facade for _self_ is returned. # user.name = "callie" # poster = user.as(Poster) # poster.name = "coco" # user.name # => "callie" def as(role, &block) facade = Facade::ObjectBuilder.new(self, role).product if block_given? block.call(facade) facade.actualize else facade end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
schizo-0.1.2 | lib/schizo/data.rb |
schizo-0.1.1 | lib/schizo/data.rb |