Sha256: 43577fdd6847c6e3aa35645cd6ee204fde5bf859ca56b69462ba5c32240b31c4
Contents?: true
Size: 1.13 KB
Versions: 3
Compression:
Stored size: 1.13 KB
Contents
module Declarative class Heritage < Array # Record inheritable assignments for replay in an inheriting class. def record(method, *args, &block) self << {method: method, args: DeepDup.(args), block: block} # DISCUSS: options.dup. end # Replay the recorded assignments on inheritor. # Accepts a block that will allow processing the arguments for every recorded statement. def call(inheritor, &block) each { |cfg| call!(inheritor, cfg, &block) } end private def call!(inheritor, cfg) yield cfg if block_given? # allow messing around with recorded arguments. inheritor.send(cfg[:method], *cfg[:args], &cfg[:block]) end module DSL def heritage @heritage ||= Heritage.new end end # To be extended into classes using Heritage. Inherits the heritage. module Inherited def inherited(subclass) super heritage.(subclass) end end # To be included into modules using Heritage. When included, inherits the heritage. module Included def included(mod) super heritage.(mod) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
declarative-0.0.8 | lib/declarative/heritage.rb |
declarative-0.0.7 | lib/declarative/heritage.rb |
declarative-0.0.6 | lib/declarative/heritage.rb |