Module: Doodle::SelfClass
- Included in:
- BaseMethods
- Defined in:
- lib/doodle.rb
Overview
provides more direct access to the singleton class and a way to treat singletons, Modules and Classes equally in a meta context
Instance Method Summary collapse
-
#sc_eval(*args, &block) ⇒ Object
evaluate in class context of self, whether Class, Module or singleton.
-
#singleton_class(&block) ⇒ Object
return the ‘singleton class’ of an object, optionally executing a block argument in the (module/class) context of that object.
Instance Method Details
#sc_eval(*args, &block) ⇒ Object
evaluate in class context of self, whether Class, Module or singleton
116 117 118 119 120 121 122 123 |
# File 'lib/doodle.rb', line 116 def sc_eval(*args, &block) if self.kind_of?(Module) klass = self else klass = self.singleton_class end klass.module_eval(*args, &block) end |
#singleton_class(&block) ⇒ Object
return the ‘singleton class’ of an object, optionally executing a block argument in the (module/class) context of that object
110 111 112 113 114 |
# File 'lib/doodle.rb', line 110 def singleton_class(&block) sc = class << self; self; end sc.module_eval(&block) if block_given? sc end |