Class: Olib::Gameobj_Extender

Inherits:
Object
  • Object
show all
Defined in:
lib/Olib/core/extender.rb

Direct Known Subclasses

Container, Creature, Item, Shop::Container

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ Gameobj_Extender

Returns a new instance of Gameobj_Extender.



5
6
7
8
# File 'lib/Olib/core/extender.rb', line 5

def initialize(item)
  self.__extend__(item)
  @type = item.type
end

Instance Attribute Details

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/Olib/core/extender.rb', line 4

def type
  @type
end

Instance Method Details

#__extend__(item) ⇒ Object

This copies GameObj data to attributes so we can employ it for scripting



11
12
13
14
15
16
17
# File 'lib/Olib/core/extender.rb', line 11

def __extend__(item)
  item.instance_variables.each { |var|
    s = var.to_s.sub('@', '')
    (class << self; self end).class_eval do; attr_accessor "#{s}"; end
    instance_variable_set "#{var}", item.send(s)
  }
end

#atObject



24
25
26
# File 'lib/Olib/core/extender.rb', line 24

def at
  fput "look at ##{@id}"
end

#echoObject



19
20
21
22
# File 'lib/Olib/core/extender.rb', line 19

def echo
  respond self
  self
end