Module: Gamefic::Scriptable::Seeds
- Included in:
- Gamefic::Scriptable
- Defined in:
- lib/gamefic/scriptable/seeds.rb
Instance Method Summary collapse
-
#construct(name, klass, **opts) ⇒ void
(also: #attr_make, #attr_seed)
Construct an entity.
-
#make(klass, **opts) ⇒ void
(also: #make_seed, #seed_make)
Add an entity to be seeded when the narrative gets instantiated.
-
#seed(*methods, &block) ⇒ Object
Set methods and procs that get executed when a narrative gets initialized.
- #seeds ⇒ Array<Proc>
Instance Method Details
#construct(name, klass, **opts) ⇒ void Also known as: attr_make, attr_seed
This method returns an undefined value.
Construct an entity.
This method adds an instance method for the entity and a class method to reference it with a proxy.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gamefic/scriptable/seeds.rb', line 35 def construct name, klass, **opts ivname = "@#{name}" define_method(name) do return instance_variable_get(ivname) if instance_variable_defined?(ivname) instance_variable_set(ivname, make(klass, **unproxy(opts))) end seed { send(name) } define_singleton_method(name) { Proxy::Attr.new(name) } end |
#make(klass, **opts) ⇒ void Also known as: make_seed, seed_make
This method returns an undefined value.
Add an entity to be seeded when the narrative gets instantiated.
52 53 54 |
# File 'lib/gamefic/scriptable/seeds.rb', line 52 def make klass, **opts seed { make(klass, **unproxy(opts)) } end |
#seed(*methods, &block) ⇒ Object
Set methods and procs that get executed when a narrative gets initialized.
22 23 24 25 |
# File 'lib/gamefic/scriptable/seeds.rb', line 22 def seed *methods, &block seeds.push(proc { methods.flatten.each { |method| send(method) } }) unless methods.empty? seeds.push block if block end |
#seeds ⇒ Array<Proc>
7 8 9 |
# File 'lib/gamefic/scriptable/seeds.rb', line 7 def seeds @seeds ||= [] end |