Class: MetaDef::Def

Inherits:
Object
  • Object
show all
Defined in:
lib/metadef/meta_def.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metaclass) ⇒ Def

Returns a new instance of Def.



14
15
16
# File 'lib/metadef/meta_def.rb', line 14

def initialize(metaclass)
  @metaclass = metaclass
end

Instance Attribute Details

#metaclassObject (readonly)

Returns the value of attribute metaclass.



11
12
13
# File 'lib/metadef/meta_def.rb', line 11

def metaclass
  @metaclass
end

#real_classObject (readonly)

Returns the value of attribute real_class.



12
13
14
# File 'lib/metadef/meta_def.rb', line 12

def real_class
  @real_class
end

Class Method Details

.build(obj) ⇒ Object



18
19
20
# File 'lib/metadef/meta_def.rb', line 18

def self.build(obj)
  new (obj.instance_eval("class << self; self; end"))
end

Instance Method Details

#accessor(name) ⇒ Object



38
39
40
41
# File 'lib/metadef/meta_def.rb', line 38

def accessor(name)
	reader name
	writer name
end

#method(name, &block) ⇒ Object



22
23
24
# File 'lib/metadef/meta_def.rb', line 22

def method(name, &block)
	metaclass.send :define_method, name, block
end

#reader(name) ⇒ Object



26
27
28
29
30
# File 'lib/metadef/meta_def.rb', line 26

def reader(name)
	method name do
		instance_variable_get("@#{name}")
	end
end

#writer(name) ⇒ Object



32
33
34
35
36
# File 'lib/metadef/meta_def.rb', line 32

def writer(name)
	method "#{name}=" do |value|
		instance_variable_set "@#{name}", value
	end
end