Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/ruck/misc/linkage.rb,
lib/ruck/misc/linkage.rb
Overview
stolen from metaid.rb: whytheluckystiff.net/articles/seeingMetaclassesClearly.html (that site does not exist, but a mirror can be found)
Instance Method Summary collapse
-
#class_def(name, &blk) ⇒ Object
Defines an instance method within a class.
- #L(&block) ⇒ Object
- #linkable_attr(attr_sym) ⇒ Object
-
#meta_def(name, &blk) ⇒ Object
Adds methods to a metaclass.
- #meta_eval(&blk) ⇒ Object
-
#metaclass ⇒ Object
The hidden singleton lurks behind everyone.
Instance Method Details
#class_def(name, &blk) ⇒ Object
Defines an instance method within a class
49 50 51 |
# File 'lib/ruck/misc/linkage.rb', line 49 def class_def name, &blk class_eval { define_method name, &blk } end |
#L(&block) ⇒ Object
30 31 32 |
# File 'lib/ruck/misc/linkage.rb', line 30 def L(&block) block end |
#linkable_attr(attr_sym) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ruck/misc/linkage.rb', line 14 def linkable_attr(attr_sym) attr_reader attr_sym define_method("#{attr_sym}=") do |val| instance_variable_set("@#{attr_sym}", val) if val.respond_to? :call attr_sym do val.call end else attr_sym do val end end end end |
#meta_def(name, &blk) ⇒ Object
Adds methods to a metaclass
44 45 46 |
# File 'lib/ruck/misc/linkage.rb', line 44 def name, &blk { define_method name, &blk } end |
#meta_eval(&blk) ⇒ Object
41 |
# File 'lib/ruck/misc/linkage.rb', line 41 def &blk; .instance_eval &blk; end |
#metaclass ⇒ Object
The hidden singleton lurks behind everyone
40 |
# File 'lib/ruck/misc/linkage.rb', line 40 def ; class << self; self; end; end |