Class: Degica::Person

Inherits:
Object
  • Object
show all
Defined in:
lib/degica/objects/people/person.rb

Direct Known Subclasses

ChuckNorris, Hacker, Jack, Matz

Instance Attribute Summary

Attributes included from Collectable

#collection

Instance Method Summary collapse

Methods inherited from Object

#prompt

Methods included from Actionable

#do, #prompt

Constructor Details

#initializePerson

Returns a new instance of Person.



3
4
5
6
# File 'lib/degica/objects/people/person.rb', line 3

def initialize
  @talked = false
  @inventory = InventoryCollection.new
end

Instance Method Details

#actionsObject



20
21
22
# File 'lib/degica/objects/people/person.rb', line 20

def actions
  [Action.new(:talk, self), Action.new(:give, self)]
end

#describeObject



52
53
54
55
56
57
# File 'lib/degica/objects/people/person.rb', line 52

def describe
  desc = []
  desc << description
  desc << "Maybe you should (talk) with him.".highlight unless @talked
  desc.join("\n")
end

#descriptionObject

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/degica/objects/people/person.rb', line 16

def description
  raise NotImplementedError
end

#give(object = nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/degica/objects/people/person.rb', line 36

def give(object = nil)
  if object.nil?
    return "What do you want to give?"
  elsif !object.is_a?(::Degica::Object)
    return "\"#{object}\" is not in your (inventory).".highlight
  end

  if object.collection.delete(object)
    @inventory << object
    puts "You gave the (#{object.name}) to #{name}.".highlight
  else
    puts "You don't have any #{object.name}."
  end
  NilActionable.new
end

#inspectObject



24
25
26
# File 'lib/degica/objects/people/person.rb', line 24

def inspect
  "#{name.capitalize} says: \"Don't inspect me!\""
end

#nameObject

Raises:

  • (NotImplementedError)


8
9
10
# File 'lib/degica/objects/people/person.rb', line 8

def name
  raise NotImplementedError
end

#quoteObject

Raises:

  • (NotImplementedError)


12
13
14
# File 'lib/degica/objects/people/person.rb', line 12

def quote
  raise NotImplementedError
end

#talkObject



28
29
30
31
32
33
34
# File 'lib/degica/objects/people/person.rb', line 28

def talk
  @talked = true
  desc = []
  desc << "#{name} says:".capitalize
  desc << '"' + quote + '"'
  desc.join(" ")
end