Module: Gamefic::Overlookable

Defined in:
lib/gamefic/overlookable.rb,
lib/gamefic/overlookable/version.rb

Overview

A mixin for implementing nouns as Scenery with a default description.

Constant Summary collapse

VERSION =
'1.0.0'

Instance Method Summary collapse

Instance Method Details

#overlook(*names, type: Scenery) ⇒ Array<Entity>

Create Scenery that provides a default description for unimplemented words. Names can include two slashes (//) to add a list of synonyms.

The type of overlookable entity can be modified with the ‘type` parameter. For compatibility with the gamefic-standard library, it is recommended to use either `Scenery` or `Rubble`.

Examples:

thing = make Thing, name: 'table', description: 'A table with cups and white china plates.'
thing.overlook 'cups', 'plates//white china'

# > look table
#
# A table with cups and white china plates.
#
# > look cups
#
# There's nothing special about the cups.
#
# > look china
#
# There's nothing special about the plates.

Parameters:

  • names (Array<String>)

    Names or name/synonym arrays

  • type (Class<Entity>) (defaults to: Scenery)

    The type of overlookable entity (default is Scenery)

Returns:

  • (Array<Entity>)


38
39
40
41
42
43
44
45
# File 'lib/gamefic/overlookable.rb', line 38

def overlook *names, type: Scenery
  names.map do |input|
    parts = input.split('//')
    name = parts[0].to_s.strip
    synonyms = parts[1].to_s.strip
    type.new(name: name, synonyms: synonyms, parent: self)
  end
end

#rubble=(names) ⇒ void

This method returns an undefined value.

A shortcut to overlookable Rubble that can be called from ‘make` parameters.

Examples:

make Thing, name: 'table',
            description: 'A table with a plate on it.',
            rubble: ['plate']

Parameters:

  • (Array<String>)


69
70
71
# File 'lib/gamefic/overlookable.rb', line 69

def rubble= names
  overlook(*names, type: Rubble)
end

#scenery=(names) ⇒ void

This method returns an undefined value.

A shortcut to overlookable Scenery that can be called from ‘make` parameters.

Examples:

make Thing, name: 'table',
            description: 'A table with a checkered design.',
            scenery: ['checkered design']

Parameters:

  • (Array<String>)


56
57
58
# File 'lib/gamefic/overlookable.rb', line 56

def scenery= names
  overlook(*names, type: Scenery)
end