-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta.rb
46 lines (40 loc) · 934 Bytes
/
meta.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module Meta
def lector(attr)
define_method attr do
instance_variable_get "@#{attr}"
end
end
def escritor(attr)
define_method "#{attr}=" do |val|
instance_variable_set "@#{attr}", val
end
end
def accesor(attr)
lector attr
escritor attr
end
end
module CreatureBuilder
def self.included(includer)
includer.send :extend, ClassMethods
define_method :initialize do
self.class.instance_variable_get("@traits").each do |trait, value|
instance_variable_set "@#{trait}", value
end
end
end
module ClassMethods
%w(life charisma strength weapon).each do |trait|
define_method trait do |default_value|
attr_reader trait
@traits ||= {}
@traits[trait] = default_value
end
end
end
end
module Familiar
def linaje
puts "Me llamo #{self.class} y mis ancestros son #{self.class.ancestors.join(", ")}"
end
end