Class: MetaDef::Def
- Inherits:
-
Object
- Object
- MetaDef::Def
- Defined in:
- lib/metadef/meta_def.rb
Instance Attribute Summary collapse
-
#metaclass ⇒ Object
readonly
Returns the value of attribute metaclass.
-
#real_class ⇒ Object
readonly
Returns the value of attribute real_class.
Class Method Summary collapse
Instance Method Summary collapse
- #accessor(name) ⇒ Object
-
#initialize(metaclass) ⇒ Def
constructor
A new instance of Def.
- #method(name, &block) ⇒ Object
- #reader(name) ⇒ Object
- #writer(name) ⇒ Object
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 = end |
Instance Attribute Details
#metaclass ⇒ Object (readonly)
Returns the value of attribute metaclass.
11 12 13 |
# File 'lib/metadef/meta_def.rb', line 11 def @metaclass end |
#real_class ⇒ Object (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) .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 |